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
添加回答
举报