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

scrapy 代理好奇怪

  •  
  •   HGladIator · 2017-05-18 13:19:35 +08:00 · 2068 次点击
    这是一个创建于 2545 天前的主题,其中的信息可能已经有所发展或是发生改变。
    取消代理没问题 能慢慢爬
    用上代理后全部超时 超时设 15s
    单独把所有代理 ip 测试一遍,没问题(超时设 5s )
    有问题的之前找到直接全删了





    我怀疑我的检测有问题
    就乱编了一个代理 ip
    结果


    所以到现在我还不明白哪里出了问题
    18 条回复    2017-05-18 17:03:12 +08:00
    panyanyany
        1
    panyanyany  
       2017-05-18 13:40:52 +08:00
    https 的请求应该不会经过 http 代理的吧
    HGladIator
        2
    HGladIator  
    OP
       2017-05-18 13:45:01 +08:00
    @Jessss
    @yxy2829

    看到你们也在用 帮我看看呗 谢谢啦
    freeminder
        3
    freeminder  
       2017-05-18 13:48:38 +08:00
    你拿 http 的代理,怎么代理 https 的流量。
    HGladIator
        4
    HGladIator  
    OP
       2017-05-18 13:51:45 +08:00
    @freeminder #3
    @panyanyany #1
    所以要用 https 的么
    freeminder
        5
    freeminder  
       2017-05-18 13:59:42 +08:00
    HGladIator
        6
    HGladIator  
    OP
       2017-05-18 14:10:35 +08:00
    @freeminder #5 是不是代理设置无效 会用本地的代替? 我随便设的代理 都可以收到响应
    freeminder
        7
    freeminder  
       2017-05-18 14:26:07 +08:00
    @HGladIator 说了你随便写的那个代理根本没生效,因为你设置了 http 请求的代理, 发了一个 https 的请求出去。你把 proxies 那个字段的 https 的 key 也配置成 http 的 key 就知道了
    HGladIator
        8
    HGladIator  
    OP
       2017-05-18 14:34:11 +08:00
    @freeminder #7 恩 我配了 好多失败的 我再试试
    pango
        9
    pango  
       2017-05-18 15:05:23 +08:00
    proxies = { "http": "http://x.x.x.x:xx", "https": "http://x.x.x.x:xx", }
    就行了
    HGladIator
        10
    HGladIator  
    OP
       2017-05-18 15:23:02 +08:00
    @pango #9 scrapy 那个 proxy 不能是 dict 的 会报错 我试过
    pango
        11
    pango  
       2017-05-18 15:50:17 +08:00
    @HGladIator 你不是在 requests 中用了 proxy 吗?如果是 scrapy 的话不存在 http,https 代理的问题的
    HGladIator
        12
    HGladIator  
    OP
       2017-05-18 15:52:42 +08:00
    @pango #11 你看第一个张图 这里的是 http 然后全部超时
    pango
        13
    pango  
       2017-05-18 15:53:52 +08:00
    另外明确一下: http 的代理服务器是可以代理 https 的流量的,https 走 http 代理通过的是隧道,对流量本身没有任何影响。

    requests 的 proxies = { "http": "http://x.x.x.x:xx", "https": "http://x.x.x.x:xx", }只是用来说明 http,https 分别走哪个代理服务器,但他们走的都可以是同一个 http 代理。
    HGladIator
        14
    HGladIator  
    OP
       2017-05-18 15:57:23 +08:00
    @HGladIator #12 谢谢你的解惑
    pango
        15
    pango  
       2017-05-18 16:06:15 +08:00
    @HGladIator get_invalid_proxies 和 test_proxies 两个 def 里面你定义了 requests 的 http 流量走 proxy,就像这样子:{ "http": "http://x.x.x.x:xx"},但是接下来却去 get 了一个 https 的网站,这个 https 的网站根本没走任何代理....
    估计还是你的代理有问题,你还是按照这个格式: proxies = { "http": "http://x.x.x.x:xx", "https": "http://x.x.x.x:xx", } 来用 requests 测试你的代理吧。
    HGladIator
        16
    HGladIator  
    OP
       2017-05-18 16:16:34 +08:00
    已经改了 跑了两个小时了 还没跑完 绝大部分都是无效的
    HGladIator
        17
    HGladIator  
    OP
       2017-05-18 16:17:15 +08:00
    @pango #15 已经改了 跑了两个小时了 还没跑完 绝大部分都是无效的
    BiggerLonger
        18
    BiggerLonger  
       2017-05-18 17:03:12 +08:00
    proxy = {'http': 'http://' + ip} ===========> proxy = {'http': ip} ?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1174 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 18:21 · PVG 02:21 · LAX 11:21 · JFK 14:21
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.