我们从Python开源项目中,提取了以下12个代码示例,用于说明如何使用settings.PROXIES。
def process_request(self, request, spider): request.meta['proxy'] = "http://http-dyn.abuyun.com:9020" # ?????????????????????????? proxy_user_pass = "HX4OS8905X90183D:C3127131D399C059" encoded_user_pass = base64.encodestring(proxy_user_pass) request.headers['Proxy-Authorization'] = 'Basic ' + encoded_user_pass #print "proxy = %s" (request.meta['proxy']) return proxy = random.choice(PROXIES) request.meta['proxy'] = "http://%s" % proxy return if proxy['user_pass'] is not None: request.meta['proxy'] = "http://%s" % proxy['ip_port'] encoded_user_pass = base64.encodestring(proxy['user_pass']) request.headers['Proxy-Authorization'] = 'Basic ' + encoded_user_pass print "**************ProxyMiddleware have pass************" + proxy['ip_port'] else: print "**************ProxyMiddleware no pass************" + proxy['ip_port'] request.meta['proxy'] = "http://%s" % proxy['ip_port'] return
def process_request(self, request, spider): proxy = random.choice(PROXIES) if proxy['user_pass'] is not None: request.meta['proxy'] = "http://%s" % proxy['ip_port'] encoded_user_pass = base64.encodestring(proxy['user_pass']) request.headers['Proxy-Authorization'] = 'Basic ' + encoded_user_pass print "**************ProxyMiddleware have pass************" + proxy['ip_port'] else: print "**************ProxyMiddleware no pass************" + proxy['ip_port'] request.meta['proxy'] = "http://%s" % proxy['ip_port']
def process_request(self, request, spider): proxy = random.choice(PROXIES) if proxy['user_pass'] is not None: request.meta['proxy'] = "http://%s" % proxy['ip_port'] encoded_user_pass = base64.encodestring(proxy['user_pass']) request.headers[ 'Proxy-Authorization'] = 'Basic ' + encoded_user_pass # print "**************ProxyMiddleware have pass************" + # proxy['ip_port'] else: # print "**************ProxyMiddleware no pass************" + # proxy['ip_port'] request.meta['proxy'] = "http://%s" % proxy['ip_port'] pass
def process_request(self, request, spider): proxy = random.choice(PROXIES) if proxy['user_pass'] is not None: request.meta['proxy'] = "http://%s" % proxy['ip_port'] encoded_user_pass = base64.encodestring(proxy['user_pass'].encode(encoding='utf-8')) request.headers['Proxy-Authorization'] = 'Basic ' + encoded_user_pass.decode() print ("**************ProxyMiddleware have pass************" + proxy['ip_port']) else: print ("**************ProxyMiddleware no pass************" + proxy['ip_port']) request.meta['proxy'] = "http://%s" % proxy['ip_port']
def process_request(self, request, spider): proxy = random.choice(PROXIES) if proxy['user_pass'] is not None: request.meta['proxy'] = "http://%s" % proxy['ip_port'] request.meta['proxy'] = "https://%s" % proxy['ip_port'] encoded_user_pass = base64.encodestring(proxy['user_pass']) request.headers['Proxy-Authorization'] = 'Basic ' + encoded_user_pass print "**************ProxyMiddleware have pass************" + proxy['ip_port'] else: print "**************ProxyMiddleware no pass************" + proxy['ip_port'] request.meta['proxy'] = "http://%s" % proxy['ip_port'] print "?????"
def process_request(self, request, spider): proxy = random.choice(PROXIES) if proxy['user_pass'] is not None: request.meta['proxy'] = "http://%s" % proxy['ip_port'] encoded_user_pass = base64.encodestring(proxy['user_pass']) request.headers['Proxy-Authorization'] = 'Basic ' + encoded_user_pass print "**************ProxyMiddleware have pass************" + proxy['ip_port'] else: print "**************ProxyMiddleware no pass************http://%s" % proxy['ip_port'] request.meta['proxy'] = "http://%s" % proxy['ip_port']
def process_request(self, request, spider): proxy = random.choice(PROXIES) if proxy['user_pass'] is not None: request.meta['proxy'] = "http://%s" % proxy['ip_port'] encoded_user_pass = base64.encodestring(proxy['user_pass']) request.headers['Proxy-Authorization'] = 'Basic ' + encoded_user_pass else: request.meta['proxy'] = "http://%s" % proxy['ip_port']
def process_request(self, request, spider): proxy = random.choice(PROXIES) request.meta['proxy'] = "http://%s" % proxy['ip_port'] #print '************using proxy:'+proxy['ip_port']
def process_request(self, request, spider): proxy = random.choice(PROXIES) if proxy['user_pass'] is not None: request.meta['proxy'] = "http://%s" % proxy['ip_port'] encoded_user_pass = base64.encodestring(proxy['user_pass']) request.headers['Proxy-Authorization'] = 'Basic ' + encoded_user_pass # print "**************ProxyMiddleware have pass************" + proxy['ip_port'] else: # print "**************ProxyMiddleware no pass************" + proxy['ip_port'] request.meta['proxy'] = "http://%s" % proxy['ip_port']
def process_request(self, request, spider): proxy = random.choice(PROXIES) if proxy['user_pass'] is None: request.meta['proxy'] = "http://%s" % proxy['ip_port'] encoded_user_pass = base64.encodestring(proxy['user_pass']) request.headers['Proxy-Authorization'] = 'Basic ' + encoded_user_pass print "**************ProxyMiddleware have pass************" + proxy['ip_port'] else: print "**************ProxyMiddleware no pass************" + proxy['ip_port'] request.meta['proxy'] = "http://%s" % proxy['ip_port']
def process_request(self, request, spider): request.meta['proxy'] = "http://%s" % random.choice(PROXIES) # proxy_user_pass = "tensor:92598866" # encode_user_pass = base64.encodestring(proxy_user_pass) # request.headers['Proxy-Authorization'] = 'Basic' + proxy_user_pass