返回信息流Chrome抓包获得的URL
Request URL:https://bbs.byr.cn/user/ajax_login.json
用urllib2或requests向这个地址post数据报404
这是一条镜像帖。来源:北邮人论坛 / python / #16941同步于 2016/12/14
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Python机器人发帖
【问题】北邮人论坛模拟登录
daisyO7xx
2016/12/14镜像同步9 回复
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
【 在 neet 的大作中提到: 】
: 记得加header = {'x-requested-with':'XMLHttpRequest'}
cookieFileName = "cookie.txt"
cookie = cookielib.MozillaCookieJar(cookieFileName)
handler = urllib2.HTTPCookieProcessor(cookie)
opener = urllib2.build_opener(handler)
postData = urllib.urlencode({
'id':'xxxxxxxxxxx',
'passwd':'xxxxxxxxxxxx' })
headers = {
":authority": "bbs.byr.cn",
":method": "POST",
":path": "/user/ajax_login.json",
":scheme:" : "https",
"accept": "application/json, text/javascript, */*; q=0.01",
"accept-encoding": "gzip, deflate, br",
"accept-language": "zh-CN, zh; q=0.8",
"content-length": "26",
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
"user-agent": user_agent,
"referer": referer,
"origin": origin,
"x-requested-with": "XMLHttpRequest"
}
req = urllib2.Request(loginUrl, postData, headers)
res = opener.open(req)
cookie.save(ignore_discard=True, ignore_expires=True)
貌似不行诶
【 在 youngsc 的大作中提到: 】
: 是body里参数不全的原因,除了账户密码,还有mode和CookieDate两个参数
是指我代码里postdata的部分?
请问如何获得这两个参数? 谢谢~
我用的是requests,加上这个没问题。。。
```Python
import requests
r_url = 'https://bbs.byr.cn/user/ajax_login.json'
#header for login
my_header = {
'x-requested-with':'XMLHttpRequest'}
byr_data = {'id':'***','passwd':'***'}
s = requests.Session()
r = s.post(r_url,data = byr_data,headers = my_header)
print r.text
```
【 在 daisyO7xx 的大作中提到: 】
:
: cookieFileName = "cookie.txt"
: cookie = cookielib.MozillaCookieJar(cookieFileName)
: ...................
【 在 daisyO7xx 的大作中提到: 】
:
: 是指我代码里postdata的部分?
: 请问如何获得这两个参数? 谢谢~
都写0,f12可以看到,我用node写的时候就需要这俩你试试
【 在 neet 的大作中提到: 】
: 我用的是requests,加上这个没问题。。。
: [md]
: ```Python
: ...................
requests可以,谢谢啦~
【 在 youngsc 的大作中提到: 】
:
: 都写0,f12可以看到,我用node写的时候就需要这俩你试试
谢谢啦,urllib2也模拟成功了,python好像不需要这两个参数就可以