Skip to content

Commit 4062933

Browse files
committed
add zhihulogin
1 parent 2fb7ce5 commit 4062933

3 files changed

Lines changed: 44 additions & 0 deletions

File tree

zhihu/__init__.py

Whitespace-only changes.

zhihu/auto_login.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# encoding: utf-8
2+
# !/usr/bin/env python
3+
4+
import requests
5+
6+
from bs4 import BeautifulSoup
7+
8+
headers = headers = {
9+
"User-Agent": "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36",
10+
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
11+
"Accept-Encoding": "gzip, deflate",
12+
"Host": "www.zhihu.com",
13+
"Upgrade-Insecure-Requests": "1",
14+
}
15+
response = requests.get("https://www.zhihu.com", headers=headers)
16+
soup = BeautifulSoup(response.content, "html.parser")
17+
xsrf = soup.find('input', attrs={"name": "_xsrf"}).get("value")
18+
print(xsrf)
19+
# print(response.content)
20+
21+
data = {
22+
"_xsrf": xsrf,
23+
"password": "xxx",
24+
"captcha": "pvRJ",
25+
"email": "xxxxxx",
26+
}
27+
# _xsrf=ef85127d992f6ea39d9817bbb7a315d4&password=lzjun854979&captcha=ENTV&email=lzjun567%40qq.com
28+
with open("text.gif", "wb") as f:
29+
f.write(requests.get("https://www.zhihu.com/captcha.gif?r=1490697036809&type=login", headers=headers).content)
30+
31+
captcha = input()
32+
33+
data['captcha'] = captcha
34+
35+
print(data)
36+
import json
37+
response = requests.post("https://www.zhihu.com/login/email", headers=headers, data=json.dumps(data))
38+
print(response.content)
39+
print(response.json().get("data").get("captcha"))
40+
print(response.json().get("data").get("account"))
41+
import re
42+
43+
s = "sdfdf 12:22:23 dsfsdf 23:23:12"
44+
print(re.compile(r"(\d{2}:\d{2}:\d{2})").findall(s))

zhihu/text.gif

3.35 KB
Loading

0 commit comments

Comments
 (0)