這一篇我會介紹一下如何解析從Requests,得到的Html原始碼,利用BeautifulSoup將原始碼轉換成DOM-Tree的結構,
使用BeautifulSoup擷取出我們要的資料
這張我的債有得還了XDD,這個章節我要拆了,介紹如何使用BeautifulSoup簡單語法
File->Settings->展開Project:PycharmProjects->Project Interpreter->點選綠色+->搜尋beautifulsoup4->點選安裝
抓取 (https://mojim.com/twy108268x5x2.htm ) 魔鏡歌詞網的歌詞
# coding=utf-8
import requests
from bs4 import BeautifulSoup
pageRequest = requests.get('https://mojim.com/twy108268x5x2.htm')
soup = BeautifulSoup(pageRequest.text, 'html.parser')
song = soup.find(id='fsZx3').text
print(song)
成功後結果
(https://www.crummy.com/software/BeautifulSoup/bs4/doc/#problems-after-installation )BeautifulSoup4 文件