1. 程式人生 > >bs4常用用法

bs4常用用法

sub lxml .get prop item 常用用法 get com itl

from bs4 import BeautifulSoup
import requests
#獲取爬去的網址
url=requests.get(‘https://movie.douban.com/subject/24773958/‘)
#獲取網頁源代碼

v_source=BeautifulSoup(url.text,‘lxml‘)
# print(v_source)
# 爬取標題
v_title=v_source.find(‘span‘,attrs={‘property‘:‘v:itemreviewed‘})
#print(v_title.text)

v_jianjie=v_source.find(‘span‘,attrs={‘property‘:‘v:summary‘})
print(v_jianjie.text)

v_leixing=v_source.find_all(‘span‘,attrs={‘property‘:‘v:genre‘})
# for i in range(len(v_leixing)):
# print(v_leixing[i].text,end=‘ ‘)

for i in v_leixing:
print(i.text)

bs4常用用法