企查查爬虫python实现(二)报错与细节
1、WebDriver object has no attribute find_element_by_xpath问题
重新安装selenium
pip show selenium # 查看版本
新电脑中卸载selenium,并安装指定版本4.2.0
pip uninstall selenium
pip install selenium==4.2.0
修改方法find_element_by_xpath
之前的写法:
wd.find_element_by_xpath('/html/body/div[3]/div[2]/div/div[1]/div[1]/div[1]/div/ul/li[2]/a')
现在的写法:
wd.find_element(By.XPATH, '/html/body/div[3]/div[2]/div/div[1]/div[1]/div[1]/div/ul/li[2]/a')
记得导入包
from selenium.webdriver.common.by import By
2、NameError: name 'NoSuchElementException' is not defined
头部加一句:from selenium.common.exceptions import NoSuchElementException 可解决
(1)为了优化速度可以加入下面的代码禁止图片加载,但是禁止了就不会出现图片验证的界面。(2)如果反扒策略失效,需要手动输入验证码才能进行爬虫,则需要屏蔽掉禁止图片加载,删除下面的代码。
option.add_experimental_option("prefs", {"profile.managed_default_content_settings.images": 2})
3、selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://chromedriver.chromium.org/home
报错代码:
driver = webdriver.Chrome(executable_path=r"/usr/bin/chromedriver", options=option)
原因 executable_path已经废除,chromedriver添加到环境变量后就直接这样写就行
driver = webdriver.Chrome(options=option)
4、DeprecationWarning: find_element_by_xpath is deprecated. Please use find_element(by=By.XPATH, value=xpath) instead
解决方法就是find_element_by_xpath 改为find_element(by=By.XPATH, value=xpath)
xpath就是对应页面元素的xpath,如下图
5、selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: invalid locator (Session info: chrome=97.0.4692.99)
能打开,但是定位的元素错误,无法点击,要检查对应的ind_element(by=By.XPATH, value=xpath)中的xpath是否写错。
6、windows总同时打开excel文件和运行读取excel文件的程序就会报错permission denied: 'xxx.xlsx'
7、如果在更新pip 的过程中pip卸载了,ModuleNotFoundError: No module named 'pip'
解决途径:
python -m ensurepip
python -m pip install --upgrade pip
8、WARNING: Ignoring invalid distribution -ip (f:\py\lib\site-packages)
python库site-packages中的文件夹中出现带~文件,删除
企查查爬虫python实现(二)报错与细节相关推荐
- Python爬虫总结——常见的报错、问题及解决方案
Python爬虫基础--HTML.CSS.JavaScript.JQuery网页前端技术 Python爬虫基础--正则表达式 Python爬虫基础--re模块的提取.匹配和替换 Python爬虫基础- ...
- python安装报错类型_解决Python安装cryptography报错问题
解决Python安装cryptography报错问题 错误一: gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wst ...
- python 读取文件报错:UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xb5 in position 0: invalid start
python 读取文件报错:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb5 in position 0: invalid start ...
- python运行启动报错解决方法_解决python运行启动报错问题
解决python运行启动报错问题 问题一: python启动报错api-ms-win-crt-process-l1-1-0.dll丢失 解决: 下载api-ms-win-crt-process-l1- ...
- 夜神模拟器打开后报错:nox_adb.exe已停止工作,Appium+Python脚本执行报错:500
一.场景回溯: 夜神模拟器打开后报错:nox_adb.exe已停止工作,Appium+Python脚本执行报错:500. 二.问题解决: 1.cmd中关闭Appium服务: 2.进入夜神模拟器安装的b ...
- python调用dll报错:ValueError: Procedure called with not enough arguments (4 bytes missing) or wrong call
python调用dll报错:ValueError: Procedure called with not enough arguments (4 bytes missing) or wrong call ...
- python导入openpyxl报错问题,终于解决啦
python导入openpyxl报错问题,终于解决啦 参考文章: (1)python导入openpyxl报错问题,终于解决啦 (2)https://www.cnblogs.com/guotang/p/ ...
- Python 中文注释报错解决方法
Python 中文注释报错解决方法 参考文章: (1)Python 中文注释报错解决方法 (2)https://www.cnblogs.com/cjiong/p/5881983.html 备忘一下.
- 神奇的python(五)之python强制退出报错(异常)解决方法
简介:python程序在执行时,有时候由于某些模块冲突或者是定时器冲突,会出现很多奇怪的错误,为此我们需要让python程序在退出时免受这些问题的干扰. (1) 常用的信号类型: SIGINT 终止进 ...
最新文章
- pom.xml增加依赖
- [原]NYOJ-开灯问题-77
- Anaconda自带Python编译器Jupyter Notebook显示代码行数
- jQuery插件编写基础之“又见弹窗”
- 静态库的冲突 duplicate symbol
- torchvision学习之torchvision.datasets
- Noise,Error,wighted pocket Algorithm
- mongodb 索引1
- C++ 课设 职工工资管理系统
- 联想g400从u盘启动计算机,联想g400怎么进bios设置u盘启动图文教程
- 9张图揭秘:优秀的数据分析项目,这样做!
- ubuntu下rsync两个服务器同步文件
- localize by triangle note
- 元宇宙虚拟数字人系统
- seo是什么意思(seo专员是什么职业?)
- Python模拟登陆京东
- 团体程序设计天梯赛 -- 练习集 (L1合集)
- 杰理之VM 概述【篇】
- java使用阿里云短信平台
- hall 状态下,禁用指纹解锁