def curl(source_url, is_post, cookie):
"""
??pycurl?????WEB???????
:source_url: ??URL
:is_post: ???POST
:cookie: cookie
"""
buffer = BytesIO()
c = pycurl.Curl()
c.setopt(c.ENCODING, 'gzip,deflate')
c.setopt(c.COOKIE, cookie)
c.setopt(c.USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:42.0) Gecko/20100101 Firefox/42.0')
try:
if is_post == 2: # post
url, query = source_url.split('?', 1)
c.setopt(c.URL, url)
c.setopt(c.POSTFIELDS, query)
else:
c.setopt(c.URL, source_url)
c.setopt(c.WRITEDATA, buffer)
c.perform()
c.close()
return buffer.getvalue()
except:
return ''
评论列表
文章目录