【发布时间】:2021-02-27 20:34:23
【问题描述】:
我正在尝试按照教程从 Quora url 中提取所有答案。我的代码是这样的
url = 'https://www.quora.com/Should-I-move-to-London'
r = requests.get(url)
soup = BeautifulSoup(r.content, 'html.parser')
answers = soup.find("script", {"type": "application/ld+json"})
answers
但是,当我尝试从答案(bs4.element.tag 对象)中获取文本时, 它只是显示为空。 如何提取所有答案? 我也尝试了以下
data = json.loads(soup.find('script', type='application/ld+json').text)
但我收到以下错误
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
【问题讨论】:
-
我刚刚尝试了你的脚本和行:
data = json.loads(soup.find('script', type='application/ld+json').text)对我来说很好 -
我试过了..但我得到了和 OP 一样的错误
标签: python html json beautifulsoup