爬蟲 資訊組織與提取方法

2022-04-08 17:53:13 字數 560 閱讀 3480

資訊標記的三種形式:

xml: 擴充套件標記語言,用<>,以標籤為主,名稱,屬性等

json:有型別的鍵值對,可以巢狀使用,可以乙個鍵對應多個值

yaml:無型別鍵值對,用縮排的形式表達所屬關係,-表示並列關係

比較xml  最早的通用資訊標記語言,可擴充套件性好,但是繁瑣;適用於internet上的資訊互動與傳遞

json  資訊有型別,適合程式處理,較xml簡潔;適用於移動應用雲端和節點的資訊通訊,無注釋

yaml  資訊無型別,文字資訊比例較高,可讀性好;適用於各類系統的配置檔案,有注釋易讀

#

下面程式設計提取以上html裡的所有鏈結

from bs4 import

beautifulsoup

soup=beautifulsoup(demo,'

html.parser')

for link in soup.find_all('a'

):

print(link.get('

href

'))

返回:

05 Python爬蟲之資訊標記與提取方法

目錄 二 資訊標記形式的比較 三 資訊提取的一般方法 四 基於bs4庫的html內容查詢方法 總結 例項 提取html中所有url鏈結 思路 搜尋到所有標籤 解析標籤格式,提取href後的鏈結內容 import requests r requests.get 得到response響應資料 demo ...

Python網路爬蟲與資訊提取(2) 爬蟲協議

上一節學習了requests庫,這一節學習robots協議 宣告robots協議,一般放在 的根目錄下,robots.txt檔案 京東robots鏈結 user agent disallow disallow pop html disallow pinpai html?user agent etao...

MOOC Python網路爬蟲與資訊提取Week1

常見異常 response 返回所有的網頁內容 r.raise for status 如果不是200,產生異常requests.httperror import requests def gethtmltext url try r requests.get url,timeout 30 r.raie...