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

scrapy 爬网站的时候 加代理报错

  •  
  •   Ewig · 2019-01-05 10:42:39 +08:00 · 2081 次点击
    这是一个创建于 1910 天前的主题,其中的信息可能已经有所发展或是发生改变。
    这个网站加了代理报错如下
    网址: http://www.csrc.gov.cn/pub/newsite/xxpl/yxpl/index

    自己的 middleware 组件
    import base64


    class proxy_middleware(object):

    def __init__(self):
    proxy_host = "t.1n.cn"
    proxy_port = "**"
    self.username = "***"
    self.password = "***"
    self.proxies = {"https": "https://{}:{}/".format(proxy_host, proxy_port)}
    self.proxy_server = 'https://w5.t.16yun.cn:6469'
    self.proxy_authorization = 'Basic ' + base64.urlsafe_b64encode(
    bytes((self.username + ':' + self.password), 'ascii')).decode('utf8')

    def process_request(self, request, spider):
    request.meta['proxy'] = self.proxy_server
    request.headers['Proxy-Authorization'] = self.proxy_authorization




    2019-01-05 10:37:46 [csrc][scrapy.downloadermiddlewares.retry] DEBUG: Retrying <GET http://www.csrc.gov.cn/pub/newsite/xxpl/yxpl/index_1.html> (failed 1 times): [<twisted.python.failure.Failure OpenSSL.SSL.Error: [('SSL routines', 'ssl3_get_record', 'wrong version number')]>]
    10 条回复    2019-01-05 14:43:45 +08:00
    xz
        1
    xz  
       2019-01-05 10:45:49 +08:00
    你们公司在哪?还招人吗?
    PulpFunction
        2
    PulpFunction  
       2019-01-05 10:46:26 +08:00
    网址都 404 了
    1n.cn 是啥代理
    Ewig
        3
    Ewig  
    OP
       2019-01-05 10:47:21 +08:00
    Ewig
        4
    Ewig  
    OP
       2019-01-05 10:48:05 +08:00
    Ewig
        5
    Ewig  
    OP
       2019-01-05 10:51:51 +08:00
    @PulpFunction 我故意写错的,是一个动态代理
    meik2333
        6
    meik2333  
       2019-01-05 11:05:24 +08:00 via Android
    难道 1n.cn 就是下面那个 w5.t.16yun.cn:6469 么?
    misaka19000
        7
    misaka19000  
       2019-01-05 11:09:15 +08:00 via Android
    又见不格式化的 python 代码,v 站的用户素质已经这样了吗?
    PulpFunction
        8
    PulpFunction  
       2019-01-05 11:30:05 +08:00
    建议你看看官方文档,我是 splashrequests
    形式如:
    SplashRequest ( url, callback, endpoint, args{lua_source.......proxy})

    你看你用什么 Request 应该大同小异

    换个代理,有的不好使
    Ewig
        9
    Ewig  
    OP
       2019-01-05 13:29:21 +08:00
    @PulpFunction 解决了,谢谢!
    gaoan000
        10
    gaoan000  
       2019-01-05 14:43:45 +08:00 via Android
    @xz 杀人诛心
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2917 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 14:09 · PVG 22:09 · LAX 07:09 · JFK 10:09
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.