日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python:beautifulSoup学习(来自学习资料)

發布時間:2024/9/27 python 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python:beautifulSoup学习(来自学习资料) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

羅列問題:
1、beautifulSoup是什么
是一個能夠快速從html或者xml文檔中獲取數據的類庫。
官方的說是,能夠幫你節省一天或者幾天的開發時間。
2、beautifulSoup如何安裝
Pip install beautifulSoup4(如果是Python3.x就是用這個)
舊版本:beautifulSoup3
Pip install beautifulSoup
3、beautifulSoup如何使用
本文中只講解通過beautifulSoup select選擇器獲取數據
還有很多其他用法,需要單獨學習。

Html基礎回顧:

標簽:緊跟著尖括號的內容
類:class
屬性:標簽中的字段
編號:id

html_doc = """ <html><head><title>The Dormouse's story</title></head> <body> <p class="title"><b>The Dormouse's story</b></p><p class="story">Once upon a time there were three little sisters; and their names were <a href="http://example.com/elsie" class="sister" id="link1">Elsie</a>, <a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and <a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>; and they lived at the bottom of a well.</p><p class="story">...</p> """

beautifulSoup.select的幾種查找數據的方式:

Soup.select(“title”) //通過標簽查找 Soup.select(“.sister”) //通過class查找 Soup.select(“#link2”)//通過id查找 Soup.select(“a[href]”) //判斷a標簽是否有href屬性

在python控制臺中使用beautifulSoup的部首
1、導入from bs4 import BeautifulSoup
2、創建一個BeautifulSoup的實例

通過標簽查找:

通過class查找

Select返回的值是一個list,需要通過角標獲取數據。

通過id查找

多個id使用逗號分隔

通過查找

方式一:
屬性固定的值

方式二:
是否包含屬性

總結

以上是生活随笔為你收集整理的python:beautifulSoup学习(来自学习资料)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。