V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
Odinlai
V2EX  ›  Python

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

  •  1
     
  •   Odinlai · 2015-09-06 16:17:09 +08:00 · 1851 次点击
    这是一个创建于 3165 天前的主题,其中的信息可能已经有所发展或是发生改变。
    大家好,我有个关于 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':'[email protected]', '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
    1 条回复    2015-09-10 16:21:12 +08:00
    qq12365411
        1
    qq12365411  
       2015-09-10 16:21:12 +08:00
    问题描述的不够清楚,你的意思是,这个他不返回数据吗?

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

    下次把你问题描述的更详细一些, 多用 10 分钟发帖,你的问题被解决的可能性会增加 10 倍
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3180 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 12:59 · PVG 20:59 · LAX 05:59 · JFK 08:59
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.