【发布时间】:2021-07-03 23:57:36
【问题描述】:
我正在尝试使用 Python 代码中的 Beautiful Soup 从 URL 中提取体育数据。我在使用此数据源时遇到的问题是数据出现在 html 标记中。具体来说,这个标签的标题是“”
我在寻找球员数据——这似乎是 XML 格式的。然而,这些数据出现在“匹配”标签中,而不是作为开始/结束标签中的内容。
像这样:
print(soup.match)
返回:(不包括所有文本):
<match :matchdata='{"match":{"id":"5dbb8e20-6f37-11eb-924a-1f6b8ad68.....ALL DATA HERE....>
</match>
因此,当我尝试将内容作为文本输出时,它返回空。
print(soup.match.text)
返回:无
如何从 "" html 标记中提取这些数据。在此之后,我想保存为 XML 文件,或者更好的是 CSV 文件。
我的python程序从一开始就是:
from bs4 import BeautifulSoup
import requests
url="___MY_URL_HERE___"
# Make a GET request for html content
html_content = requests.get(url).text
# Parse the html content
soup = BeautifulSoup(html_content, "lxml")
## type(soup)
## <class 'bs4.BeautifulSoup'>
print(soup.match)
非常感谢!
【问题讨论】:
-
您能否在帖子中包含网址以及预期输出。
标签: python xml parsing beautifulsoup