ip是为“182.90.80.137:8123”相同格式的字符串
火狐浏览器:
-
ip_ip = ip.split(":")[0]
-
ip_port = int(ip.split(":")[1])
-
print(ip_ip)
-
print(ip_port)
-
random_header = random.choice(HEADERS)
-
webdriver.DesiredCapabilities.FIREFOX['firefox.page.settings.userAgent'] = random_header
-
profile = webdriver.FirefoxProfile()
-
profile.set_preference('network.proxy.type', 1) # 默认值0,就是直接连接;1就是手工配置代理。
-
profile.set_preference('network.proxy.http', ip_ip)
-
profile.set_preference('network.proxy.http_port', ip_port)
-
profile.set_preference('network.proxy.ssl', ip_ip)
-
profile.set_preference('network.proxy.ssl_port', ip_port)
-
profile.update_preferences()
-
driver = webdriver.Firefox(profile)
谷歌浏览器:
-
chromedriver = 'C:/Program Files (x86)/Google/Chrome/Application/chromedriver.exe'
-
chome_options = webdriver.ChromeOptions()
-
chome_options.add_argument(('--proxy-server=http://' + ip))
-
os.environ["webdriver.chrome.driver"] = chromedriver
-
driver = webdriver.Chrome(chromedriver, chrome_options=chome_options)