重慶分公司,新征程啟航
為企業提供網站建設、域名注冊、服務器等服務
為企業提供網站建設、域名注冊、服務器等服務
小編給大家分享一下使用python中beautifulsoup庫的示例,希望大家閱讀完這篇文章后大所收獲,下面讓我們一起去探討吧!
老規矩,先學會安裝:
方式:pip install beautifulsoup4
測試是否安裝成功:
import requests r = requests.get("鏈接") demo = r.text form bs4 import BeautifulSoup soup = BeautifulSoup(demo, "html.parser")
實例案例演示:
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}')
看完了這篇文章,相信你對使用python中beautifulsoup庫的示例有了一定的了解,想了解更多相關知識,歡迎關注創新互聯行業資訊頻道,感謝各位的閱讀!