Python 利用 requests 登录站点的问题。

2015-09-06 16:17:09 +08:00
 Odinlai
大家好,我有个关于 python 的问题想要求助,在这里已经卡两天了,希望有经验的大侠们能帮忙看看。

我想要作一个消息的确认器,这是给自己的练习,利用 requests 登入站点,确认是否有未读的新消息带浏览。我以前用 requests 也爬过几个网站,大部分一 post 出去,页面就乖乖吐出来了,我觉得一定是我缺少某方面的基础知识。

下面是代码,使用的帐号是测试用的帐号,各位如果愿意,也可以直接拿来测试:

import requests
import re

header_info ={

'Cache-Control': 'max-age=0',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Origin':' https://weavi.com',
'Upgrade-Insecure-Requests': '1',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64 ) AppleWebKit/537.36 (KHTML, like Gecko ) Chrome/44.0.2403.157 Safari/537.36',
'Content-Type': 'application/x-www-form-urlencoded',
'Accept-Encoding': 'gzip, deflate',
'Referer':'https://weavi.com/',
'Accept-Language': 'en-US,en;q=0.8',

}


myS = requests.session ()

r= myS.get ("https://weavi.com")

XSRF= re.findall ('name="csrf-param" />\n<meta content=".+?" name="csrf-token" />',r.text,re.S )

XSRF_str= XSRF[0][36:-22]

login_data = {'username':'Vasilyluan@gmail.com', 'password':'W03211230','redirect':'https://weavi.com/','authenticity_token':XSRF_str}

r=myS.post ("https://weavi.com/login",data=login_data )

r=myS.get ("https://weavi.com/")

message = re.findall ('unread_messages',r.text,re.S )

print message
1863 次点击
所在节点    Python
1 条回复
qq12365411
2015-09-10 16:21:12 +08:00
问题描述的不够清楚,你的意思是,这个他不返回数据吗?

网络正常吗?
返回为空?
还是返回什么错误?错误编号多少?
chrome 的 F12 抓出来 需要的参数都附带了吗? 别说你不会用 chrome 的 F12

下次把你问题描述的更详细一些, 多用 10 分钟发帖,你的问题被解决的可能性会增加 10 倍

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

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

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

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

© 2021 V2EX