gpt4 book ai didi

python - 如何在 Firefox Webdriver 中永久设置代理

转载 作者:行者123 更新时间:2023-12-04 09:01:17 26 4
gpt4 key购买 nike

由于我无法直接从 Geckodriver 设置代理,我将通过使用手动更改它

from selenium import webdriver


myProxy = "xxxxxxxxx:yyyy"
ip, port = myProxy.split(":")


profile = webdriver.FirefoxProfile()
profile.set_preference('network.proxy_type',5)
profile.set_preference('network.proxy.http','xxxxxxxxx')
profile.set_preference('network.proxy.http_port',yyyy)
profile.update_preferences()

driver=webdriver.Firefox(firefox_profile=profile)
driver.get('http://www.google.co.th')
time.sleep(3)
driver.close()
我正在尝试执行,firefox 已更改为代理模式
但是,当我通过 Robot Framework 执行脚本时,它也通过 Geckodriver 执行,它不会更改为代理。
我需要知道在 Geckodriver 中永久更改代理的方法

最佳答案

与 SeleniumLibrary 的 Open Browser关键字,您可以像在 Python 脚本中一样设置任何首选项。
例如,以下测试每次都会使用这些选项打开浏览器:

  • 代理 HTTP 端口设置为 777。
  • 代理类型设置为“5”。
  • 代理 HTTP“xxxxxxxxx”。
  • *** Settings ***
    Library SeleniumLibrary

    *** Test Cases ***
    Test
    Open Browser http://example.com Firefox ff_profile_dir=set_preference("network.proxy_type", "5");set_preference("network.proxy.http", "xxxxxxxxx");set_preference("network.proxy.http_port", 777) # Defining profile using FirefoxProfile mehtods.
    Sleep 1 min reason=Verify proxy settings manually in the opened browser.
    sleep 期间在 Firefox 的 about:config 页面上检查的值:
    enter image description here

    关于python - 如何在 Firefox Webdriver 中永久设置代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63554862/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com