我已经在python中编写了一个与selenium结合使用的脚本来从网页中获取一个文本块,在该网页中写入了我的刮刀通过代理发送请求的文本块。
例如:如果请求不是通过代理发送的,那么文本应该出现在控制台中就像'This request appears NOT to have come via a proxy.', 'The request appears to have originated from ip address [my_ip_address]'
这就是我所拥有的。
如何通过代理运行我的刮刀?提前谢谢。
脚本我尝试过:
from selenium import webdriver
proxies = {
'http': 'http://163.172.27.213:3128',
'https': 'https://163.172.175.210:3128'
}
chrome_options = webdriver.ChromeOptions()
proxy_arg = ';'.join(['{}={}'.format(k, v) for k, v in proxies.items()])
chrome_options.add_argument('--proxy-server="{}"'.format(proxy_arg))
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get('http://www.lagado.com/proxy-test')
items = [item.text for item in driver.find_elements_by_css_selector(".main-panel p")[:2]]
print(items)
driver.quit()
答案 0 :(得分:2)
from selenium import webdriver
proxy = "12.12.12.12:1212" # IP:PORT or HOST:PORT
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=%s' % proxy)
chrome = webdriver.Chrome(chrome_options=chrome_options)
chrome.get("http://www.google.com")