1、扒取網頁
req = requests.get(url = target) html = req.text bf = BeautifulSoup(html,'html.parser') texts = bf.find_all('a') print(texts)
2、輸出結果
3、F12查看原頁面
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4、估計是默認使用的編碼不對,頁面內容取回後先指定解碼方式,試試。
代碼:
req = requests.get(url = target) req.encoding='utf-8' #指定編碼格式,解決中文亂碼顯示 html = req.text bf = BeautifulSoup(html,'html.parser') texts = bf.find_all('a') print(texts)
結果:
5、問題解決