求教,这个模拟登陆为什么是 403?

2016-04-22 20:06:45 +08:00
 wex

http://i.imgur.com/Kwva2jp.png http://i.imgur.com/cpi6xIT.png http://i.imgur.com/1nS1SA1.png

3083 次点击
所在节点    Python
9 条回复
wex
2016-04-22 20:07:15 +08:00
wex
2016-04-22 20:07:26 +08:00
这个咋么编辑?
wex
2016-04-22 20:12:42 +08:00
caspartse
2016-04-23 00:15:04 +08:00
eoo
2016-04-23 02:47:17 +08:00
PHP 搞起
wex
2016-04-23 10:11:27 +08:00
@caspartse 还是 403
ming2281
2016-04-23 10:24:13 +08:00
与题目无关的几点
找 login-url 时一定要找对,具体是查看 chrome 控制台的 Request-URL 那里
使用 requests, 从此模拟登陆不要太简单!(幸福感大大提升) 读读其文档,也就一两小时, 神兵利器
caspartse
2016-04-23 11:03:03 +08:00
@wex

#!/usr/bin/env python
# -*- coding:UTF-8 -*
import requests
import re
import simplejson as json


session = requests.Session()
url = 'http://account.lvye.cn/accounts/login'
response = session.get(url)
content = response.content
pattern = r'<input type=\'hidden\' name=\'csrfmiddlewaretoken\' value=\'([^\s]+?)\' />'
token = re.search(pattern, content).group(1)
data = {
'username': 'ly233',
'password': 'ly233233',
'cap_code': '',
'auto': 'on',
'csrfmiddlewaretoken': token,
'next': 'http://lvye.cn',
'client_id': 'None',
'state': 'None',
'cap_key': '',
'login_code': ''
}
url = 'http://account.lvye.cn/accounts/ajax_login/'
response = session.post(url, data=data)
content = response.content
result = json.loads(content)
print 'uid: %s , username: %s , email: %s' % (result.get('uid'), result.get('name'), result.get('email'))
wex
2016-04-23 13:25:14 +08:00
@caspartse
谢谢!!!

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/273732

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX