class ProxyMiddleware(object): # overwrite process request def
process_request(self, request, spider):
# Set the location of the proxy
request.meta['proxy'] = "127.0.0.1:8123"
def start_reqests():
yield Request('http://checkip.dyndns.org/', callback=self.check_ip)
# yield other requests from start_urls here if needed
def check_ip(self, response):
pub_ip = response.xpath('//body/text()').re('\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}')[0]
print "My public IP is: " + pub_ip
# yield other requests here if needed
您可以发出第一个请求来检查您的公共IP,并将其与在不使用Tor/VPN的情况下转到http://checkip.dyndns.org/时看到的IP进行比较。如果它们不一样,scrapy显然使用了不同的IP。
最快的方法是使用^{} 并检查
meta
是否包含proxy
。从项目根目录开始:
这样您就可以检查中间件配置是否正确,请求是否通过代理。
相关问题 更多 >
编程相关推荐