diff --git a/auth.py b/auth.py index ed51290..f6f6763 100644 --- a/auth.py +++ b/auth.py @@ -68,7 +68,15 @@ def __init__(self, message): def download_captcha(): url = "https://www.zhihu.com/captcha.gif" - r = requests.get(url, params={"r": random.random(), "type": "login"}, verify=False) + headers = { + 'User-Agent': "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36", + 'Host': "www.zhihu.com", + 'Origin': "http://www.zhihu.com", + 'Pragma': "no-cache", + 'Referer': "http://www.zhihu.com/", + 'X-Requested-With': "XMLHttpRequest" + } + r = requests.get(url, params={"r": random.random(), "type": "login"}, verify=False, headers=headers) if int(r.status_code) != 200: raise NetworkError(u"验证码请求失败") image_name = u"verify." + r.headers['content-type'].split("/")[1] @@ -96,7 +104,15 @@ def download_captcha(): def search_xsrf(): url = "http://www.zhihu.com/" - r = requests.get(url, verify=False) + headers = { + 'User-Agent': "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36", + 'Host': "www.zhihu.com", + 'Origin': "http://www.zhihu.com", + 'Pragma': "no-cache", + 'Referer': "http://www.zhihu.com/", + 'X-Requested-With': "XMLHttpRequest" + } + r = requests.get(url, verify=False, headers=headers) if int(r.status_code) != 200: raise NetworkError(u"验证码请求失败") results = re.compile(r"\