小编new*_*111的帖子

使用 BeautifulSoup 获取 span 标签的值

我有许多 facebook 群组,我想了解其成员的数量。一个例子是这个组:https : //www.facebook.com/groups/347805588637627/ 我看过页面上的检查元素,它是这样存储的:

<span id="count_text">9,413 members</span>
Run Code Online (Sandbox Code Playgroud)

我试图从页面中删除“9,413 名成员”。我曾尝试使用 BeautifulSoup,但无法解决。

谢谢

编辑:

from bs4 import BeautifulSoup
import requests

url = "https://www.facebook.com/groups/347805588637627/"
r  = requests.get(url)
data = r.text
soup = BeautifulSoup(data, "html.parser")
span = soup.find("span", id="count_text")
print(span.text)
Run Code Online (Sandbox Code Playgroud)

html python parsing beautifulsoup python-3.x

10
推荐指数
2
解决办法
3万
查看次数

标签 统计

beautifulsoup ×1

html ×1

parsing ×1

python ×1

python-3.x ×1