【问题标题】:Firefox GeckoDriver not accepting HTTP Proxy IP with user authenticationFirefox GeckoDriver 不接受带有用户身份验证的 HTTP 代理 IP
【发布时间】:2019-11-28 08:36:40
【问题描述】:

所以我有下面的代码,它仍然显示真实 IP。也没有产生错误。抱歉无法分享真实的代理详细信息:)

from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy, ProxyType
from selenium.webdriver.firefox.options import Options
PROXY_HOST = "206.41.127.230"

PROXY_PORT = "603230"

USERNAME = "xxx"

PASSWORD = "xx"

profile = webdriver.FirefoxProfile()

profile.set_preference("network.proxy.type", 1)

profile.set_preference("network.proxy.http", PROXY_HOST)

profile.set_preference("network.proxy.http_port", PROXY_PORT)

profile.set_preference("network.proxy.socks_username", USERNAME)

profile.set_preference("network.proxy.socks_password", PASSWORD)

options = Options()
options.headless = True
driver = webdriver.Firefox(options=options, executable_path=r'/usr/local/bin/geckodriver', firefox_profile=profile)
driver.get('https://httpbin.org/ip')
html = driver.page_source
print(html)
driver.quit()

【问题讨论】:

  • 您的 PROXY_PORT 是一个字符串。不应该是整数吗?而且你的端口号真的有六位数吗?
  • 它是 Python。是的,一个六位数的端口

标签: python selenium http-proxy geckodriver firefox-profile


【解决方案1】:

看来你很接近了。您需要为 FirefoxProfile 实例 profile 调用 update_preferences(),您可以使用以下解决方案:

from selenium import webdriver

PROXY_HOST = "206.41.127.230"
PROXY_PORT = "6032"
USERNAME = "xxx"
PASSWORD = "xx"

profile = webdriver.FirefoxProfile()
profile.set_preference('network.proxy.type', 1)
profile.set_preference("network.proxy.http", PROXY_HOST)
profile.set_preference("network.proxy.http_port", PROXY_PORT)
profile.set_preference("network.proxy.socks_username", USERNAME)
profile.set_preference("network.proxy.socks_password", PASSWORD)
profile.update_preferences()
options = webdriver.FirefoxOptions()
options.headless = True
driver = webdriver.Firefox(options=options, executable_path=r'/usr/local/bin/geckodriver', firefox_profile=profile)
driver.get('https://httpbin.org/ip')
html = driver.page_source
print(html)
driver.quit()

参考

您可以在以下位置找到相关讨论:

【讨论】:

  • 不适合我...我不知道为什么。它仍在返回真实 IP 地址。
  • 当我通过requests 使用代理时,我使用代理 URL 作为proxy_url = 'https://u:password@' + random_proxy.rstrip('\n') - HTTPS
猜你喜欢
  • 2012-06-10
  • 2017-01-15
  • 1970-01-01
  • 1970-01-01
  • 2012-08-24
  • 2017-10-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多