【发布时间】:2019-03-06 17:52:01
【问题描述】:
我正在尝试使用 BeautifulSoup 提取 Python3 中 ('script', type='application/ld+json') 的 @context 元素中的文本。
我在一页中有多个脚本,我想获得上面 json 中列出的特定功能。
我尝试使用此代码:
data = soup.find_all('script', type='application/ld+json')
print(data)
这给了我所有脚本的完整提取内容,但我想在每个脚本的上下文中获得一个特定的功能。
功能示例:
{"name":"test","telephone":"600.212.0000","url":"https://test.com/test"}
对于这个例子,我想获得"url" 部分。
有人知道用 Python 做吗?
非常感谢您的帮助。
【问题讨论】:
标签: python json web-scraping beautifulsoup findall