記錄學習python爬蟲遇到的問題

2021-08-19 20:39:12 字數 603 閱讀 5618

1,urllib

碰到的第乙個問題就是python3不支援urllib.urlope()方法,解決方法是引用urillib.request.urlopen();

2,爬取的網頁中文顯示x89/x86/x45

python3輸出位串,而不是可讀的字串,需要轉化,使用str(string,'ecoding')進行轉化就可一解決

3,對urllib中的data引數進行構造

需要引入urllib下的parse,同時需要記住提交型別不能是string,應該是byte型別。寫法:parse.urlencode(data).encode('編碼型別')

4,python 報錯 typeerror:an integer is required (got type dict)

原因:headers不能用urllib.request.urlopen()直接訪問,需要先用urllib.request.request()

5,threading.current_thread()詳解

6,多執行緒:threading.current_thread().name和.getname()有什麼區別

解答:name 是當前執行緒的屬性, getname 是當前執行緒的方法。

python爬蟲入門學習記錄

在使用爬蟲前確保requests和beautifulsoup4模組都已經安裝好了 pip install requests pip install beautifulsoup4 beautifulsoup4使用手冊 簡單的示列 import requests 匯入requests包 url strh...

記錄一次簡單python爬蟲遇到的問題

1.python版本問題。2.爬蟲ip被封。這次我用了兩種思路。乙個是更換 就是指定header,使用fake useragent包的useragent來隨機使用header。還有一種是使用ip 和的requests方法,不知道為什麼urllib是不可以的。3.儲存問題。是採用mongodb來進行儲...

python小白學習記錄 爬蟲requests篇

一 引用庫 import requests 二 請求訪問url,網頁相應 res requests.get 網頁位址 三 表明返回內容 目前返回的response物件有四種屬性 status code 檢查請求是否成功 content 將資料轉換為二進位制資料 text 將資料轉換為字串型資料 en...