fpg*_*ost 13 python firefox proxy selenium headless
我正在使用像这样的Firefox无头:
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium import webdriver
import os
import sys
# Set the MOZ_HEADLESS environment variable which casues Firefox to
# start in headless mode.
os.environ['MOZ_HEADLESS'] = '1'
# Select your Firefox binary.
binary = FirefoxBinary('/usr/bin/firefox', log_file=sys.stdout)
# Start selenium with the configured binary.
driver = webdriver.Firefox(firefox_binary=binary)
Run Code Online (Sandbox Code Playgroud)
但现在我想添加一个需要用户/密码的http代理.搜索后,我尝试了以下内容:
from selenium.webdriver.common.proxy import Proxy, ProxyType
myProxy = "xx.xx.xx.xx:80"
proxy = Proxy({
'proxyType': ProxyType.MANUAL,
'httpProxy': myProxy,
'ftpProxy': myProxy,
'sslProxy': myProxy,
'noProxy': '' # set this value as desired
})
driver = webdriver.Firefox(firefox_binary=binary, proxy=proxy)
Run Code Online (Sandbox Code Playgroud)
我也试过了
profile = webdriver.FirefoxProfile()
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.http", "xx.xx.xx.xx")
profile.set_preference("network.proxy.http_port", 80)
profile.update_preferences()
driver=webdriver.Firefox(firefox_binary=binary,firefox_profile=profile)
Run Code Online (Sandbox Code Playgroud)
最后,我尝试添加"socksUsername"和"socksPassword"以及proxy更多的绝望,而不是任何真正的希望.
不用说,这些都不起作用,测试显示请求仍然使用我常用的IP,而不是代理.
在这种情况下,系统范围的代理也不是一个选项.
http代理凭证应该在哪里?如何使用无头firefox的代理?
测试
driver.get("https://www.ipinfo.io");
driver.find_element_by_xpath('//h4/following-sibling::p').text
Run Code Online (Sandbox Code Playgroud)
您是否尝试过手动设置配置文件
./firefox --ProfileManager
Run Code Online (Sandbox Code Playgroud)
手动设置代理,然后加载您手动设置的配置文件
from selenium import webdriver
url = "https://mail.google.com"
fp = webdriver.FirefoxProfile('/Users/<username>/Library/Application Support/Firefox/Profiles/71v1uczn.default')
driver = webdriver.Firefox(fp)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2133 次 |
| 最近记录: |