如何使用python从外部HTML(web站点)获取代码片段

2024-09-28 21:32:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用python从HTML网站上获取一个片段。你知道吗

例如,从urlhttp://steven-universe.wikia.com/wiki/Steven_Universe_Wiki我想得到“下一集”框中的文本,作为字符串。我怎样才能得到它?你知道吗


Tags: 字符串文本com网站htmlwikiuniversesteven
1条回答
网友
1楼 · 发布于 2024-09-28 21:32:30

首先从here下载BeautifulSoup最新版本 以及来自here的请求

from bs4 import BeautifulSoup
import requests

con = requests.get(url).content
soup = BeautifulSoup(con)
text = soup.find_all("a",href="/wiki/Gem_Harvest").text;
print(link)

相关问题 更多 >