正在获取代理使用的IP地址



我有以下代码:

API_KEY = 'YOUR_API_KEY'
proxy_options = {
'proxy': {
'http': f'http://scraperapi:{API_KEY}@proxy-server.scraperapi.com:8001',
'https': f'http://scraperapi:{API_KEY}@proxy-server.scraperapi.com:8001',
'no_proxy': 'localhost,127.0.0.1'
}
}
driver = webdriver.Chrome(seleniumwire_options=proxy_options)
wait = WebDriverWait(driver, 20)
driver.get(url)
# Rest of the code

如何在每次运行driver.get(url)时打印IP?

一个更简单的方法是将ChromeDriver启动的谷歌chrome浏览上下文的初始化封装在for循环中,如下所示:

API_KEY = 'YOUR_API_KEY'
proxy_options = {
'proxy': {
'http': f'http://scraperapi:{API_KEY}@proxy-server.scraperapi.com:8001',
'https': f'http://scraperapi:{API_KEY}@proxy-server.scraperapi.com:8001',
'no_proxy': 'localhost,127.0.0.1'
}
}
my_url_list = ['https://www.google.com/', 'https://stackoverflow.com/']
for url in my_url_list:
try:
driver = webdriver.Chrome(seleniumwire_options=proxy_options)
wait = WebDriverWait(driver, 20)
driver.get(url)
print(driver.current_url)
except:
continue

最新更新