Skip to content

Commit

Permalink
修改知乎模拟登陆过程代码
Browse files Browse the repository at this point in the history
  • Loading branch information
ResolveWang committed Mar 30, 2017
1 parent fd335f4 commit 5245953
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions zhihu_login/do_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,41 @@
# 知乎登陆的时候并没有在前台做过多的加密,只是每次捕捉了它的xsrf就行了,和csdn的模拟登陆一样
session = requests.session()

#要提交的参数
headers = {
"User_Agent":"Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.75 Safari/537.36",
"refer":"http://www.zhihu.com/"
}

#从原始界面拿到 _xsrf,第一次post
get_url = 'http://www.zhihu.com/#signin'

phone_num = '****'
password = '****'
# 要提交的参数
headers = {
"User-Agent": ("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/602.4.8 (KHTML, like Gecko) "
"Version/10.0.3 Safari/602.4.8"),
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Host": 'www.zhihu.com',
'Accept-Language': 'zh-cn',
"Accept-Encoding": 'gzip, deflate',
'Cache-Control': 'max-age=0',
'Upgrade-Insecure-Requests': '1'
}

# 从原始界面拿到 _xsrf,第一次post
get_url = 'https://www.zhihu.com/#signin'

phone_num = input('请输入你的用户名')
password = input('请输入你的密码')
remember_me = 'true'

xsrf_url = session.get(get_url, headers=headers).text

xsrf_url = session.get(get_url,headers=headers).text
soup_one = BeautifulSoup(xsrf_url,'html.parser')
xsrf = soup_one.body.find('div',{'class':'index-main'}).find('div',{'class':'index-main-body'}).form.find('input',{'name':'_xsrf'}).attrs['value']
soup_one = BeautifulSoup(xsrf_url, 'html.parser')
xsrf = soup_one.body.find('div', {'class': 'index-main'}).find('div', {'class': 'index-main-body'}).form.find('input', {
'name': '_xsrf'}).attrs['value']

post_data1 = {
'phone_num': phone_num,
'password': password,
'remember_me': remember_me,
'_xsrf': xsrf
}
'phone_num': phone_num,
'password': password,
'remember_me': remember_me,
'_xsrf': xsrf
}

r = session.post('http://www.zhihu.com/login/phone_num', data=post_data1, headers=headers)
r = session.post('https://www.zhihu.com/login/phone_num', data=post_data1, headers=headers)

if r.status_code == 200:
print('模拟登陆成功')
else:
print('模拟登陆失败')





0 comments on commit 5245953

Please sign in to comment.