2 回答

TA貢獻1818條經驗 獲得超11個贊
以下是這類工作最常用的庫:
$?pip?install?requests?bs4
在您最喜歡的 IDE 中:
import requests
from bs4 import BeautifulSoup
r = requests.get("http://www.python.org")
soup = BeautifulSoup(r.content, "html.parser")
sometag = soup.find("sometag")
print(sometag)

TA貢獻1847條經驗 獲得超7個贊
嘗試這個。
import requests
url = "https://stackoverflow.com/questions/63577634/extract-html-and-search-in-python"
res = requests.get(url)
print(res.text)

TA貢獻1845條經驗 獲得超8個贊
另一種方法。
from simplified_scrapy import SimplifiedDoc,req
html = req.get('https://www.python.org')
doc = SimplifiedDoc(html)
title = doc.getElement('title').text
print (title)
title = doc.getElementByText('Welcome to', tag='title').text
print (title)
結果:
Welcome to Python.org
Welcome to Python.org
添加回答
舉報