使用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)
相关推荐
IT古董6 分钟前
《Agent开发工程师成长指南》- 第4章 第6节:Prompt模板设计——如何把零散的提示词变成可复用的工程资产?
运维·服务器·数据库
骑着蜗牛撵大象32737 分钟前
从0实现C++ AI大模型接入SDK(十):DataManager业务实现——数据库CRUD、事务管理与数据一致性
数据库·c++·人工智能·sqlite·事务管理·数据一致性
阿正的梦工坊1 小时前
深入理解 B+ Tree:从二叉搜索树、B Tree 到数据库索引的底层原理
数据库
夜雪一千1 小时前
PostgreSQL 的触发器如何写
linux·数据库·postgresql
codeejun2 小时前
每日一Go·MySQL-28、账户转账事务设计
开发语言·mysql·golang
IvorySQL2 小时前
PostgreSQL 日报|拟废弃 money 类型(12 月 3 日)
数据库·postgresql
箓维2 小时前
MySQL_数据类型
数据库·mysql
LabVIEW开发2 小时前
中大型 LabVIEW 软件怎么分层?界面层、业务层、数据层的拆法与红线
linux·数据库·labview
啵啵啵鱼2 小时前
IT疑难杂症诊疗室:从现象到根因的排障方法论
数据库
RestCloud2 小时前
目标端已有数据处理,覆盖/合并/跳过三种策略选择
服务器·数据库·数据仓库·etl·etlcloud·数据传输·数据集成平台