Site icon 腳本酒

python basic crawler

python 基礎爬蟲

寫爬蟲之前要先安裝三個套件: requests , BeautifulSoup,  lxml
pip不行的話可以用easy_install

 pip install lxml
 pip install requests
 pip install BeautifulSoup4

驗證是否安裝成功
lxml

requests

BeautifulSoup4

 import requests
 from bs4 import BeautifulSoup
 import lxml

再去寫爬蟲

r1=requests.get('https://www.youtube.com/watch?v=9SY16YbteM0')
soup=BeautifulSoup(r1.text,'lxml')
print soup    #顯示全部網址
result = soup.select('網頁元素')
print result   #顯示所選元素的程式碼

套件安裝介紹      函示庫介紹

Exit mobile version