def query(url):
output = io.BytesIO()
query = pycurl.Curl()
query.setopt(pycurl.URL, url)
query.setopt(pycurl.HTTPHEADER, getHeaders())
query.setopt(pycurl.PROXY, 'localhost')
query.setopt(pycurl.PROXYPORT, SOCKS_PORT)
query.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS5_HOSTNAME)
query.setopt(pycurl.WRITEFUNCTION, output.write)
through = False
while not through:
try:
query.perform()
http_code = query.getinfo(pycurl.HTTP_CODE)
if http_code == 200:
through = True
else:
# renew tor to retry
print 'error httpcode:' +str(http_code)
renew_tor()
# time.sleep(3)
except pycurl.error as exc:
print "pycurl error in tor.py %s" % exc
# return "Unable to reach %s (%s)" % (url, exc)
return output.getvalue()
评论列表
文章目录