使用undetected-chromedriver报错遇到的问题及解决方法,以及它使用SOCKS代理的问题

文章讲述了在Python3.8.10环境中使用undetected-chromedriver时遇到的HTTP404错误,通过升级Selenium和undetected-chromedriver版本解决了问题,并提供了设置代理的方法。
摘要由CSDN通过智能技术生成

环境:python3.8.10

uc的安装方法:

pip38 install undetected-chromedriver

上测试代码:

import undetected_chromedriver as uc
driver = uc.Chrome()
driver.get('https://www.baidu.com')
driver.save_screenshot('baidu.png')

报错:

urllib.error.HTTPError: HTTP Error 404: Not Found

经查询,应该是版本问题和更新问题。

解决问题的参考链接:urllib.error.HTTPError: HTTP Error 404: Not Found · Issue #565 · ultrafunkamsterdam/undetected-chromedriver · GitHub

解决方法两步走:

(1)pip38 install selenium==4.9.0

(2)pip38 install --upgrade undetected-chromedriver

然后,查看确认下selenium和undetected-chromedriver的版本。

pip38.exe show selenium
pip38.exe show undetected-chromedriver

这时,就应该可以正常运行了。

如果还有问题,可能就是chrome浏览器版本的问题。有网友给出如下解决方案(我未尝试)。

最后,记录一下uc使用代理的方法。

import undetected_chromedriver as uc
from selenium.webdriver.support.ui import WebDriverWait
from selenium import webdriver
from selenium.webdriver.edge.service import Service
from webdriver_manager.microsoft import EdgeChromiumDriverManager
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

host='127.0.0.1'
port='10808'
chrome_options = Options()#如果是from selenium.webdriver.edge.options import Options,打开edge;如果是from selenium.webdriver.chrome.options import Options,打开chrome
chrome_options.add_argument("--proxy-server=socks5://" + host + ":" + port)

driver = uc.Chrome(chrome_options=chrome_options)
#driver = webdriver.Chrome(options=chrome_options)#高版本的selenium使用的是options=chrome_options
url = "https://www.google.com/"
driver.maximize_window() #浏览器最大化
driver.get(url)

  • 6
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值