2012-12-03 23 views

回答

4

您可以爲此創建一些中間件。例如:

#Start your middleware class 
class ProxyMiddleware(object): 

# overwrite process request 
def process_request(self, request, spider): 

    # Set the location of the proxy 
    request.meta['proxy'] = "http://123.456.789.012" 

    # Use the following lines if your proxy requires authentication 
    proxy_user_pass = "USER_AND_PASS" 

    # setup basic authentication for the proxy 
    encoded_user_pass = base64.encodestring(proxy_user_pass) 
    request.headers['Proxy-Authorization'] = 'Basic ' + encoded_user_pass 

我相信,你可以很容易地通過修改上面的代碼中隨機代理網址,用戶名和密碼。如果您需要任何其他幫助,請告知我。

相關問題