码迷,mamicode.com
首页 > 其他好文 > 详细

scrapy设置ip池问题

时间:2018-04-21 17:31:52      阅读:454      评论:0      收藏:0      [点我收藏+]

标签:nes   设置   choice   ip池   代码   url   ceshi   cpi   class   

middlewares.py

import random, base64

class ProxyMiddleware(object):

    proxyList = [61.129.70.131 , 120.204.85.29]

    def process_request(self, request, spider):
        # Set the location of the proxy
        pro_adr = random.choice(self.proxyList)
        print("USE PROXY -> "+pro_adr)
        request.meta[proxy] = "http://"+ pro_adr

setting.py

DOWNLOADER_MIDDLEWARES = {
#    ceshisc.middlewares.CeshiscDownloaderMiddleware: 543,
# scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware:123,
ceshisc.middlewares.ProxyMiddleware: 100,
scrapy.contrib.downloadermiddleware.httpproxy.HttpProxyMiddleware: 110
}
ITEM_PIPELINES = {
   ceshisc.pipelines.CeshiscPipeline: 300,
}

小蜘蛛代码

import scrapy

class DmozSpider(scrapy.Spider):
    name = "demo"
    allowed_domains = ["baidu.com"]
    start_urls = [http://www.baidu.com/]
    

    def parse(self, response):
        print("进来了...........数据")

 

scrapy设置ip池问题

标签:nes   设置   choice   ip池   代码   url   ceshi   cpi   class   

原文地址:https://www.cnblogs.com/dahuag/p/8902043.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!