铁雪资源网 Design By www.gsvan.com

应用 Scrapy框架 ,配置动态IP处理反爬。

# settings 配置中间件
DOWNLOADER_MIDDLEWARES = {
  'text.middlewares.TextDownloaderMiddleware': 543,
  # 'text.middlewares.RandomUserAgentMiddleware': 544,
  # 'text.middlewares.CheckUserAgentMiddleware': 545,
  'text.middlewares.ProxyMiddleware': 546,
  'text.middlewares.CheckProxyMiddleware': 547
}

 
# settings 配置可用动态IP
PROXIES = [
  "http://101.231.104.82:80",
  "http://39.137.69.6:8080",
  "http://39.137.69.10:8080",
  "http://39.137.69.7:80",
  "http://39.137.77.66:8080",
  "http://117.191.11.102:80",
  "http://117.191.11.113:8080",
  "http://117.191.11.113:80",
  "http://120.210.219.103:8080",
  "http://120.210.219.104:80",
  "http://120.210.219.102:80",
  "http://119.41.236.180:8010",
  "http://117.191.11.80:8080"
]
# middlewares 配置中间件
import random

class ProxyMiddleware(object):

  def process_request(self, request, spider):
    ip = random.choice(spider.settings.get('PROXIES'))
    print('测试IP:', ip)
    request.meta['proxy'] = ip


class CheckProxyMiddleware(object):

  def process_response(self, request, response, spider):
    print('代理IP:', request.meta['proxy'])
    return response

标签:
Scrapy,动态代理IP,Scrapy,,代理IP

铁雪资源网 Design By www.gsvan.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
铁雪资源网 Design By www.gsvan.com

评论“Scrapy 配置动态代理IP的实现”

暂无Scrapy 配置动态代理IP的实现的评论...