당신이 pycurl에 대해 묻는 것을 알고 있지만 사용하기에 너무 어렵고 사용하기가 어렵습니다. API가 이상합니다.
from twisted.web.client import Agent
from twisted.internet import reactor, defer
def get_headers(response, url):
'''Extract a dict of headers from the response'''
return url, dict(response.headers.getAllRawHeaders())
def got_everything(all_headers):
'''print results and end program'''
print dict(all_headers)
reactor.stop()
agent = Agent(reactor)
urls = (line.strip() for line in open('urls.txt'))
reqs = [agent.request('HEAD', url).addCallback(get_headers, url) for url in urls if url]
defer.gatherResults(reqs).addCallback(got_everything)
reactor.run()
이 예는 비동기 적으로 모든 요청을 시작하고, 모든 결과를 수집 :
는 여기 twisted 예입니다. 여기에 3 개 URL을 가진 파일의 출력입니다 : 내가 사용하는 것
{'http://debian.org': {'Content-Type': ['text/html; charset=iso-8859-1'],
'Date': ['Thu, 04 Mar 2010 13:27:25 GMT'],
'Location': ['http://www.debian.org/'],
'Server': ['Apache'],
'Vary': ['Accept-Encoding']},
'http://google.com': {'Cache-Control': ['public, max-age=2592000'],
'Content-Type': ['text/html; charset=UTF-8'],
'Date': ['Thu, 04 Mar 2010 13:27:25 GMT'],
'Expires': ['Sat, 03 Apr 2010 13:27:25 GMT'],
'Location': ['http://www.google.com/'],
'Server': ['gws'],
'X-Xss-Protection': ['0']},
'http://stackoverflow.com': {'Cache-Control': ['private'],
'Content-Type': ['text/html; charset=utf-8'],
'Date': ['Thu, 04 Mar 2010 13:27:24 GMT'],
'Expires': ['Thu, 04 Mar 2010 13:27:25 GMT'],
'Server': ['Microsoft-IIS/7.5']}}
글쎄, 당신은 파이썬이 아닌 C의 /의 ASM을 사용하는 것과 동일한 이유 - 좋네요/일을 더 쉽게 만들 수 있습니다. – nosklo
타사 모듈을 사용하는 방법을 찾고 배우는 데 소요되는 유형을 고려할 때 이러한 작은 문제에 대한 절약은별로 없습니다. – mikerobi
그건 논쟁이 아닙니다. 또한 내장 된 모듈을 배우면 시간이 같아집니다. 그리고이 경우와 같이 어떤 경우에는 품질이 떨어질 수 있습니다. – nosklo