使用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)
相关推荐
陌上丨7 小时前
Redis的Key和Value的设计原则有哪些?
数据库·redis·缓存
AI_56787 小时前
AWS EC2新手入门:6步带你从零启动实例
大数据·数据库·人工智能·机器学习·aws
ccecw7 小时前
Mysql ONLY_FULL_GROUP_BY模式详解、group by非查询字段报错
数据库·mysql
JH30737 小时前
达梦数据库与MySQL的核心差异解析:从特性到实践
数据库·mysql
数据知道7 小时前
PostgreSQL 核心原理:如何利用多核 CPU 加速大数据量扫描(并行查询)
数据库·postgresql
麦聪聊数据9 小时前
Web 原生架构如何重塑企业级数据库协作流?
数据库·sql·低代码·架构
未来之窗软件服务9 小时前
数据库优化提速(四)新加坡房产系统开发数据库表结构—仙盟创梦IDE
数据库·数据库优化·计算机软考
Goat恶霸詹姆斯10 小时前
mysql常用语句
数据库·mysql·oracle
大模型玩家七七10 小时前
梯度累积真的省显存吗?它换走的是什么成本
java·javascript·数据库·人工智能·深度学习
曾经的三心草11 小时前
redis-9-哨兵
数据库·redis·bootstrap