haipproxy icon indicating copy to clipboard operation
haipproxy copied to clipboard

求scrapy中间件

Open gsoec opened this issue 7 years ago • 2 comments

gsoec avatar Apr 20 '18 07:04 gsoec

这个需求您可以直接使用py_cli.py进行对接啊

ResolveWang avatar Apr 21 '18 01:04 ResolveWang

@gsoec 用py_cli.py里面的ProxyFetcher,不到10行代码就可以实现。

from haipporoxy.client import ProxyFetcher

class CustomProxyMiddleware(HttpProxyMiddleware):
    fetcher = ProxyFetcher('zhihu', strategy='greedy', length=5)

    def process_request(self, request, spider):
        proxy = self.fetcher.get_proxy()
        print "**************ProxyMiddleware no pass************" + proxy
        request.meta['proxy'] = self.fetcher.get_proxy()

yuxiaorui avatar Sep 20 '18 12:09 yuxiaorui