小編給大家分享一下使用python中beautifulsoup庫(kù)的示例,希望大家閱讀完這篇文章后大所收獲,下面讓我們一起去探討吧!
老規(guī)矩,先學(xué)會(huì)安裝:
方式:pip install beautifulsoup4
測(cè)試是否安裝成功:
import requests r = requests.get("鏈接") demo = r.text form bs4 import BeautifulSoup soup = BeautifulSoup(demo, "html.parser")
實(shí)例案例演示:
html = bs4.BeautifulSoup(response.text, features='lxml') note_list = html.find_all('ul', class_='note-list', limit=1)[0] for a in note_list.select('li>div.content>a.title'): title = a.contents[0] link = f'鏈接{a["href"]}' print(f'《{title}》,{link}')
看完了這篇文章,相信你對(duì)使用python中beautifulsoup庫(kù)的示例有了一定的了解,想了解更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!