Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用代理运行python selenium脚本时出现问题_Python_Python 3.x_Selenium_Web Scraping_Proxy - Fatal编程技术网

使用代理运行python selenium脚本时出现问题

使用代理运行python selenium脚本时出现问题,python,python-3.x,selenium,web-scraping,proxy,Python,Python 3.x,Selenium,Web Scraping,Proxy,我已经用python和selenium编写了一个脚本,从一个网页中获取一个文本块,其中写到我的scraper是否通过代理发送请求 例如:如果请求不是通过代理发送的,那么控制台中的文本应该类似于“此请求似乎不是通过代理发送的”,“请求似乎来自ip地址[my_ip_address]”,这就是我正在使用的 如何通过代理运行我的scraper?提前谢谢 我尝试过的脚本: from selenium import webdriver proxies = { 'http': 'http://163

我已经用python和selenium编写了一个脚本,从一个网页中获取一个文本块,其中写到我的scraper是否通过代理发送请求

例如:如果请求不是通过代理发送的,那么控制台中的文本应该类似于
“此请求似乎不是通过代理发送的”,“请求似乎来自ip地址[my_ip_address]”
,这就是我正在使用的

如何通过代理运行我的scraper?提前谢谢

我尝试过的脚本:

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()
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")