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

环境: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)
相关推荐
倔强的石头_15 小时前
kingbase备份与恢复实战(二)—— sys_dump库级逻辑备份与恢复(Windows详细步骤)
数据库
jiayou642 天前
KingbaseES 实战:深度解析数据库对象访问权限管理
数据库
于眠牧北2 天前
MySQL的锁类型,表锁,行锁,MVCC中所使用的临键锁
mysql
李广坤3 天前
MySQL 大表字段变更实践(改名 + 改类型 + 改长度)
数据库
Turnip12024 天前
深度解析:为什么简单的数据库"写操作"会在 MySQL 中卡住?
后端·mysql
爱可生开源社区4 天前
2026 年,优秀的 DBA 需要具备哪些素质?
数据库·人工智能·dba
随逸1774 天前
《从零搭建NestJS项目》
数据库·typescript
加号35 天前
windows系统下mysql多源数据库同步部署
数据库·windows·mysql
シ風箏5 天前
MySQL【部署 04】Docker部署 MySQL8.0.32 版本(网盘镜像及启动命令分享)
数据库·mysql·docker
李慕婉学姐5 天前
Springboot智慧社区系统设计与开发6n99s526(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。
数据库·spring boot·后端