在入門爬蟲的時候遇到不少問題,和不是唯一的解決方法的方法,總結整理一下,供大家學習交流,
-
syntaxerror: invalid syntax語法錯誤:無效語法
-
syntaxerror: unexpected EOF while parsing語法錯誤:多了無法決議的符號(檢查是否多了或少了括號)
-
syntaxerror: invalid character in identifier語法錯誤:有無效識別符號(檢查中文符號)
-
indexerror: list index out of range索引錯誤:串列超出索引范圍(檢查串列是否為空)
-
typeerror: must be str, not int型別錯誤:資料不是正確的資料型別,比如字串和數字直接拼接(檢查資料型別)
-
indentationerror: expected an indented block縮進錯誤:檢查代碼的縮進是否正確
-
valueerror: substring not found值錯誤:輸入的資料型別跟要求不符合
-
nameerror: name ‘a’ is not defined未初始化物件,變數沒有被定義
-
attributeerror: ‘tuple’ object has no attribute 'remove’屬性錯誤:該物件沒有這個屬性、方法(檢查資料型別)
10.網頁出現亂碼,出現亂碼的原因是因為網頁解碼程序中沒有設定如何編碼
1)response.encoding = response.apparent_encoding
11.請求頭引數
InvalidHeader: Invalid return character or leading space in header: User-Agent
import requests
headers = {
'User-Agent': ' Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4128.3 Safari/537.36'
}
response = requests.get('http://www.shuquge.com/txt/8659/index.html', headers=headers)
response.encoding = response.apparent_encoding
html = response.text
print(html)
其實很難發現問題在哪,但事實上是因為‘ Mozilla’之前多了個空格,把空格刪去即可
12. requests.exceptions.ConnectionError: HTTPConnectionPool(host=‘134.175.188.27’, port=5010): Max retries exceeded with url: /get (Caused by NewConnectionError(’<urllib3.connection.HTTPConnection object at 0x0000023AB83AC828>: Failed to establish a new connection: [WinError 10061] 由于目標計算機積極拒絕,無法連接,’,))
目標計算機積極拒絕
被識別了
網址輸入錯誤了
服務器停止提供服務器了
總的來說,一定要耐心,沒有解決不了的問題,興趣是最好的方法,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/177023.html
標籤:AI
上一篇:計算機網路作業總結10.15
下一篇:外貿建站需要注意什么?
