使用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)
相关推荐
小宇成长录6 分钟前
Mysql:数据库和表增删查改基本语句
数据库·mysql·数据库备份
团儿.1 小时前
解锁MySQL高可用新境界:深入探索MHA架构的无限魅力与实战部署
数据库·mysql·架构·mysql之mha架构
程序猿小D1 小时前
第二百六十七节 JPA教程 - JPA查询AND条件示例
java·开发语言·前端·数据库·windows·python·jpa
权^2 小时前
MySQL--聚合查询、联合查询、子查询、合并查询(上万字超详解!!!)
大数据·数据库·学习·mysql
Code成立3 小时前
1、深入理解Redis线程模型
数据库·redis·bootstrap
缘友一世4 小时前
macos安装mongodb
数据库·mongodb·macos
万事大吉CC6 小时前
mysql单表查询·3
数据库·mysql
bin91536 小时前
【EXCEL数据处理】000010 案列 EXCEL文本型和常规型转换。使用的软件是微软的Excel操作的。处理数据的目的是让数据更直观的显示出来,方便查看。
大数据·数据库·信息可视化·数据挖掘·数据分析·excel·数据可视化
Miqiuha7 小时前
lock_guard和unique_lock学习总结
java·数据库·学习
一 乐8 小时前
学籍管理平台|在线学籍管理平台系统|基于Springboot+VUE的在线学籍管理平台系统设计与实现(源码+数据库+文档)
java·数据库·vue.js·spring boot·后端·学习