# Python 爬蟲基礎知識
● Python 爬蟲基礎知識
安裝爬蟲庫
beautifulsoup4
pip install beautifulsoup4html
lxml HTML 解析器
pip install html5libhtml5
html5lib
pip install html5lib
● 使用庫
設置 encoding='utf-8' 編碼編碼
1 # -*- coding: UTF-8 -*- 2 from bs4 import BeautifulSoup 3 import lxml 4 html_file = open('text.html',encoding='utf-8') 5 6 soup = BeautifulSoup(html_file, "lxml") 7 8 for item in soup.find_all('span'): 9 print(item.attrs) 10 11 html_file.close() 12