python爬蟲常見錯誤集合
前言
python爬蟲中會遇到一些錯誤,如下是一些錯誤的集合
python常見錯誤
1. AttributeError: ‘WebDriver’ object has no attribute ‘find_element_by_id’
1. 問題描述
from selenium import webdriver path = 'chromedriver.exe' browser = webdriver.Chrome(path) url = 'https://www.baidu.com' browser.get(url) # 元素定位 # 根據(jù)id來找到對象 button = browser.find_elements_by_id('su') print(button)
如上所示,在使用selenium模塊的時候,沒有find_elements_by_id
這個函數(shù)了
2. 解決辦法
- 修改模塊內(nèi)容
- 學(xué)習(xí)模塊新的語法
2. selenium:DeprecationWarning: executable_path has been deprecated, please pass in
1. 問題描述
from selenium import webdriver path = 'chromedriver.exe' browser = webdriver.Chrome(path) url = 'https://www.baidu.com' browser.get(url) button = browser.find_elements('tag name', 'span') print(button)
Selenium經(jīng)過版本更新之后,在使用如上寫法時,系統(tǒng)就會報錯
executable_path has been deprecated, please pass in a Service object
如下所示:
2. 解決辦法
按照如下的寫法
from selenium.webdriver.chrome.service import Service from selenium import webdriver path = Service('chromedriver.exe') browser = webdriver.Chrome(service=path) url = 'https://www.baidu.com' browser.get(url) # 元素定位 # 根據(jù)id來找到對象 button = browser.find_elements('tag name', 'span') print(button)
3. 下載了包卻出現(xiàn)ModuleNotFoundError: No module named ‘requests’
1.問題描述
如下是我已經(jīng)安裝了requests后的代碼,卻出現(xiàn)
No module named 'requests'
意思就是包沒有被找到,先看如下的這張圖片:
如果沒有勾選可用于所有項(xiàng)目,那么你新建的項(xiàng)目可能會出現(xiàn)包安裝了,確報錯的情況
2. 解決辦法
4. 下載了包的時候出現(xiàn)Could not find a version that satisfies the requirement 包名
1.問題描述
下載ipython的時候出現(xiàn)
ERROR: Could not find a version that satisfies the requirement ipython (from ve rsions: none) ERROR: No matching distribution found for ipython
2. 解決辦法
pip install ipython -i https://pypi.tun a.tsinghua.edu.cn/simple/
在下載的后面添加指定的源
總結(jié)
以上為個人經(jīng)驗(yàn),希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
python類別數(shù)據(jù)數(shù)字化LabelEncoder?VS?OneHotEncoder區(qū)別
這篇文章主要為大家介紹了機(jī)器學(xué)習(xí):數(shù)據(jù)預(yù)處理之將類別數(shù)據(jù)數(shù)字化的方法LabelEncoder?VS?OneHotEncoder區(qū)別詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-09-09Python中實(shí)現(xiàn)定時任務(wù)詳解
這篇文章主要介紹了Python中實(shí)現(xiàn)定時任務(wù)詳解的相關(guān)資料,需要的朋友可以參考下2023-07-07Python列表list操作相關(guān)知識小結(jié)
今天,本喵帶大家仔細(xì)溫習(xí)一下Python的列表,溫故而知新,不亦說乎,需要的朋友可以參考下2020-01-01python網(wǎng)絡(luò)爬蟲實(shí)戰(zhàn)
實(shí)踐來源于理論,做爬蟲前肯定要先了解相關(guān)的規(guī)則和原理,網(wǎng)絡(luò)爬蟲又稱為網(wǎng)頁蜘蛛,網(wǎng)絡(luò)機(jī)器人,更經(jīng)常的稱為網(wǎng)頁追逐者,是一種按照一定的規(guī)則,自動地抓取萬維網(wǎng)信息的程序或者腳本。一句話概括就是網(wǎng)上信息搬運(yùn)工。本篇文章帶你深入了解,需要的朋友可以參考下2021-09-09Python中時間datetime的處理與轉(zhuǎn)換用法總結(jié)
今天小編就為大家分享一篇關(guān)于Python中時間datetime的處理與轉(zhuǎn)換用法總結(jié),小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2019-02-02Python導(dǎo)入數(shù)值型Excel數(shù)據(jù)并生成矩陣操作
這篇文章主要介紹了Python導(dǎo)入數(shù)值型Excel數(shù)據(jù)并生成矩陣操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-06-06python實(shí)現(xiàn)感知機(jī)模型的示例
這篇文章主要介紹了python實(shí)現(xiàn)感知機(jī)模型的示例,幫助大家更好的理解和學(xué)習(xí)python 機(jī)器學(xué)習(xí)的相關(guān)知識,感興趣的朋友可以了解下2020-09-09