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

咨询 python3 urllib,访问不了

  •  
  •   kingmo888 · 2016-07-09 22:43:14 +08:00 · 2250 次点击
    这是一个创建于 2865 天前的主题,其中的信息可能已经有所发展或是发生改变。

    http://www.czce.com.cn/portal/exchange/2015/datadaily/20151111.htm

    为何这个地址抓到的结果是

    b'<html><head><title>Request Rejected</title></head><body>The requested URL was rejected. Please consult with your administrator.

    Your support ID is: 13212746783469538584</body></html>'

    构建了一个常规的 header

    请教。。谢谢。

    4 条回复    2016-07-10 16:02:18 +08:00
    linauror
        1
    linauror  
       2016-07-09 23:00:47 +08:00
    设置 headers 即可,主要是 user_agent
    okKO
        2
    okKO  
       2016-07-09 23:28:40 +08:00
    Jblue
        3
    Jblue  
       2016-07-10 10:03:04 +08:00
    抓包分析一下
    raycool
        4
    raycool  
       2016-07-10 16:02:18 +08:00
    import requests

    url='http://www.czce.com.cn/portal/exchange/2015/datadaily/20151111.htm'
    header = {
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/601.5.17 (KHTML, like Gecko) Version/9.1 Safari/601.5.17'
    }
    r= requests.get(url,headers=header)
    print r.text

    我说网址这么顺眼,原来前东家。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5725 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 07:39 · PVG 15:39 · LAX 00:39 · JFK 03:39
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.