相关疑难解决方法(0)

使用Python的Selenium:为firefox输入/提供http代理密码

我想使用selenium和受密码保护的代理.代理不是固定的,而是一个变量.所以这必须在代码中完成(只需在这台特定的机器上设置firefox以使用代理就不太理想了).到目前为止,我有以下代码:

fp = webdriver.FirefoxProfile()
# Direct = 0, Manual = 1, PAC = 2, AUTODETECT = 4, SYSTEM = 5
fp.set_preference("network.proxy.type", 1)

fp.set_preference("network.proxy.http", PROXY_HOST)
fp.set_preference("network.proxy.http_port", PROXY_PORT)

driver = webdriver.Firefox(firefox_profile=fp)
driver.get("http://whatismyip.com")
Run Code Online (Sandbox Code Playgroud)

此时,弹出对话框,请求代理用户/通过.

是否有一种简单的方法:

  1. 在对话框中键入user/pass.
  2. 在较早阶段提供用户/通行证.

python firefox selenium selenium-webdriver

20
推荐指数
2
解决办法
2万
查看次数

使用selenium和Chrome设置代理服务器

如何使用selenium和谷歌浏览器使用代理服务器?我附加了代码,我不确定这是否会改变实际的代理服务器.

# selenium imports
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import random

PROXY ="88.157.149.250:8080";


chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=%s' % PROXY)
# //a[starts-with(@href, 'https://www.amazon.com/')]/@href
LINKS_XPATH = '//*[contains(@id,"result")]/div/div[3]/div[1]/a'
browser = webdriver.Chrome(executable_path="C:\\Users\Andrei\Downloads\chromedriver_win32\chromedriver.exe",
                           chrome_options=chrome_options)
browser.get(
    'https://www.amazon.com/s/ref=lp_11444071011_nr_p_8_1/132-3636705-4291947?rh=n%3A3375251%2Cn%3A%213375301%2Cn%3A10971181011%2Cn%3A11444071011%2Cp_8%3A2229059011')
links = browser.find_elements_by_xpath(LINKS_XPATH)
for link in links:
    href = link.get_attribute('href')
    print(href)
Run Code Online (Sandbox Code Playgroud)

python proxy selenium google-chrome

3
推荐指数
1
解决办法
1万
查看次数