推荐学习书目
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 · Sep 6, 2015 · 2368 views
    This topic created in 3968 days ago, the information mentioned may be changed or developed.
    大家好,我有个关于 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 replies    2015-09-10 16:21:12 +08:00
    qq12365411
        1
    qq12365411  
       Sep 10, 2015
    问题描述的不够清楚,你的意思是,这个他不返回数据吗?

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

    下次把你问题描述的更详细一些, 多用 10 分钟发帖,你的问题被解决的可能性会增加 10 倍
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2346 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 00:38 · PVG 08:38 · LAX 17:38 · JFK 20:38
    ♥ Do have faith in what you're doing.