Skip to content

Instantly share code, notes, and snippets.

@leopard627
Last active November 10, 2017 08:02
Show Gist options
  • Save leopard627/dfea6bd23b8069c4aa381c9013196e8f to your computer and use it in GitHub Desktop.
Save leopard627/dfea6bd23b8069c4aa381c9013196e8f to your computer and use it in GitHub Desktop.
PyCurl googleproxy.py
def _Read(self, url):
'''?????? ??? ? ?????????? ?????'''
attemptsCount = 2
for _ in range(attemptsCount):
try:
buf = cStringIO.StringIO()
curl = pycurl.Curl()
curl.setopt(pycurl.HTTPHEADER, ["Accept:"])
curl.setopt(pycurl.FOLLOWLOCATION, 1)
curl.setopt(pycurl.MAXREDIRS, 5)
curl.setopt(pycurl.CONNECTTIMEOUT, self.timeout)
curl.setopt(pycurl.TIMEOUT, self.timeout)
if self.type == 'http':
curl.setopt(pycurl.PROXY, self.address)
curl.setopt(pycurl.URL, url)
curl.setopt(pycurl.WRITEFUNCTION, buf.write)
curl.setopt(pycurl.USERAGENT, 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)')
curl.perform()
return buf.getvalue()
except Exception as error:
self.lastError = str(error)
return ''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment