1. 程式人生 > >python功能筆記——爬蟲

python功能筆記——爬蟲

python 爬蟲

python爬蟲
from bs4 import BeautifulSoup
import requests
url=‘http://www.baidu.com‘
wb_data = requests.get(url)
soup = BeautifulSoup(wb_data.text,‘lxml‘)
titles = soup.select(‘div.property_title > a[target="_blank"]‘)
imgs = soup.select(‘img[width="160"]‘)
cates = soup.select(‘div.pl3n_reasoning_v2‘)

for title,img,cate in zip(titles,imgs,cates):
data = {
‘title‘:title.get_text(),
‘img‘:img.get(‘src‘),
‘cate‘:list(cate.stripped_strings),
}
print(data)

python功能筆記——爬蟲