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
jianghu52
V2EX  ›  Python

smzdm 的自动签到挂了,但是为什么挂没想明白

  •  
  •   jianghu52 · 2015-04-22 10:56:36 +08:00 · 5794 次点击
    这是一个创建于 3263 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我连open都open不了,挂自然是理所当然的。但是为什么不能open。没想明白。
    报错的结果是 http error 521。。。。 什么鬼!
    8 条回复    2015-04-24 10:16:13 +08:00
    omoyouo
        1
    omoyouo  
       2015-04-22 11:19:43 +08:00
    怎么弄得,我也想搞个自动签到
    rse43
        2
    rse43  
       2015-04-22 11:22:30 +08:00
    看看521里的js吧,把cookie从js里提取出来设置进去就可以往下走了。 不过选个5xx的code来做bot防护还真是奇葩,怎么也应该是2xx或者3xx。
    jianghu52
        3
    jianghu52  
    OP
       2015-04-22 11:59:07 +08:00
    @rse43 问题是我现在连open都open不了,怎么得到cookie啊。
    hisway
        4
    hisway  
       2015-04-22 16:58:25 +08:00
    @jianghu52 cookie是你请求的内容,根据521返回的js组cookie数据提交。
    ca1n
        5
    ca1n  
       2015-04-23 10:23:44 +08:00
    看看正常请求和程序请求发的包吧
    aru
        6
    aru  
       2015-04-23 11:16:55 +08:00   ❤️ 1
    headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36'}
    session = requests.session()
    session.headers=headers
    r = session.get('http://www.smzdm.com/')
    e = 'c.push\("(.*?)"\)'
    m = re.findall(e,r.content)
    c = ''.join(m)
    session.cookies['__jsl_clearance'] = c
    r = session.get('http://www.smzdm.com/')
    print r

    接下来可以正常用原来的请求了
    jianghu52
        7
    jianghu52  
    OP
       2015-04-24 08:18:37 +08:00
    @aru 你跑是正常的么。我跑的话还是报错。
    在session.get 那行就错了。
    [ File "D:/Dropbox/python_file/read_text/test2_smzdm.py", line 31, in run2
    r = session.get('http://www.smzdm.com/')
    File "C:\Python27\lib\site-packages\requests\sessions.py", line 477, in get
    return self.request('GET', url, **kwargs)
    File "C:\Python27\lib\site-packages\requests\sessions.py", line 465, in request
    resp = self.send(prep, **send_kwargs)
    File "C:\Python27\lib\site-packages\requests\sessions.py", line 573, in send
    r = adapter.send(request, **kwargs)
    File "C:\Python27\lib\site-packages\requests\adapters.py", line 415, in send
    raise ConnectionError(err, request=request)
    ]
    是我导入的requests 包不对?
    aru
        8
    aru  
       2015-04-24 10:16:13 +08:00
    @jianghu52 当然正常的
    你这个看起来是网络问题呀
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3190 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 13:05 · PVG 21:05 · LAX 06:05 · JFK 09:05
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.