设置Selenium代理时遇到问题

问题描述 投票:0回答:0

爬maoyan_film的资料时,遇到selenium代理设置问题。因为我的ip被猫眼禁止了。 我设置了selenium的代理,但是总是报错,不知道怎么解决

这里有两个错误。每次我尝试测试 ip 时,它总是显示这个。网页的href显示

'data;,'
,没看懂。 enter image description here enter image description here 留言1:

selenium.common.exceptions.WebDriverException:消息:未知错误:> net::ERR_PROXY_CONNECTION_FAILED (会话信息:chrome=112.0.5615.138) 网站:Chrome 这是我的代码:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options

with open('ipaddress.txt', 'r') as f:
    iplist = f.readlines()
    for i in iplist:
        ip=i.strip('\n')
        driver_path = r'\chromedriver.exe'
        service = Service(driver_path)
        chrome_options = Options()
        chrome_options.add_argument('--headless')
        chrome_options.add_argument('--proxy-server=http://%s' % ip)
        driver = webdriver.Chrome(service=service, options=chrome_options)
        driver.get('http://httpbin.org/ip')
        if 'origin' in driver.page_source:
            print(ip)

我想知道如何修复我的代码。

python selenium-webdriver web-crawler
© www.soinside.com 2019 - 2024. All rights reserved.