Selenium Firefox代理设置带有身份验证
我正在尝试将请求发送带有代理的请求,问题是,如果我使用IP:端口代理,我的脚本也可以正常工作,但是如果我使用IP:端口也要求用户名和密码,那么我的脚本无法连接网站。
如何使用Firefox Selenium正确设置代理?
这是代码:
import time
from stem import Signal
from stem.control import Controller
from selenium.webdriver import Firefox
from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options
# profile_path = r'C:\Users\hp\Desktop\temp\FirefoxPortable\Data'
options=Options()
# options.set_preference('profile', profile_path)
options.set_preference('network.proxy.type', 1)
options.set_preference('network.proxy.socks', 'myhostgoes here')
options.set_preference('network.proxy.socks_port',12323)
options.set_preference("network.proxy.socks_username",'myusername goes here')
options.set_preference("network.proxy.socks_password",'Password goes here')
options.set_preference('network.proxy.socks_remote_dns', True)
service = Service(r'C://SeleniumDrivers/geckodriver.exe')
driver = Firefox(service=service, options=options)
driver.get("https://www.whoer.net")
time.sleep(15)
driver.close()
driver = Firefox(service=service, options=options)
driver.get("https://www.whoer.net")
I am trying to send request with proxies, the problem is, if I use IP:Port proxies, my script work fine, but if I use IP:Port which ask for username and password too, that case my script unable to connect website.
How can I set up proxies properly with Firefox Selenium?
Here is the code:
import time
from stem import Signal
from stem.control import Controller
from selenium.webdriver import Firefox
from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options
# profile_path = r'C:\Users\hp\Desktop\temp\FirefoxPortable\Data'
options=Options()
# options.set_preference('profile', profile_path)
options.set_preference('network.proxy.type', 1)
options.set_preference('network.proxy.socks', 'myhostgoes here')
options.set_preference('network.proxy.socks_port',12323)
options.set_preference("network.proxy.socks_username",'myusername goes here')
options.set_preference("network.proxy.socks_password",'Password goes here')
options.set_preference('network.proxy.socks_remote_dns', True)
service = Service(r'C://SeleniumDrivers/geckodriver.exe')
driver = Firefox(service=service, options=options)
driver.get("https://www.whoer.net")
time.sleep(15)
driver.close()
driver = Firefox(service=service, options=options)
driver.get("https://www.whoer.net")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论