How to use PROXY_LIST with password in Scrapy?

2019-08-12 13:47发布

I need to use different proxies to avoid being banned.

i read this question and this one

i put my proxies in proxylist.txt

http://xx.xx.xxx.xxx:port
http://xxx.xxx.xx.xxx:port
http://xx.xx.xxx.xxx:port
http://xxx.xxx.xx.xxx:port

and i set it in custom_settings

class MyClass(scrapy.Spider):
    reload(sys)
    sys.setdefaultencoding('utf8')
    start_time = time.time()
    name = 'mySpider'
    custom_settings = {
        'ROBOTSTXT_OBEY'    : 'False',
        'RETRY_TIMES'       : 10,
        'PROXY_LIST'        : 'proxylist.txt',
        'PROXY_MODE'        : 0,
        'DOWNLOADER_MIDDLEWARES' : {
            'scrapy.downloadermiddlewares.retry.RetryMiddleware': 90,
            'scrapy_proxies.RandomProxy': 100,
            'scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware': 110,
            'scrapy_crawlera.CrawleraMiddleware': 600,
            'scrapy.contrib.downloadermiddleware.useragent.UserAgentMiddleware': None,
            'random_useragent.RandomUserAgentMiddleware': 400
        },
    }

this version worked when my proxies had no Passwords

Now i have the password for each proxy, how can i change it for working with password ?

标签: proxy scrapy
1条回答
Fickle 薄情
2楼-- · 2019-08-12 14:19

I answer my own question.

I use this and it works:

http://USERNAME:PASSWORD@PROXYIP:PROXYPORT
查看更多
登录 后发表回答