【发布时间】:2021-02-22 21:21:53
【问题描述】:
我正在尝试从各种 AMC 测试中提取问题。以https://artofproblemsolving.com/wiki/index.php/2002_AMC_10B_Problems/Problem_1 为例。要获得问题文本,我只需要第一个
元素中的常规字符串文本和第一个
元素中的 中的乳胶。
到目前为止我的代码:
res = requests.get('https://artofproblemsolving.com/wiki/index.php/2016_AMC_10B_Problems/Problem_1')
soup = bs4.BeautifulSoup(res.text, 'html.parser')
latex_equation = soup.select('p img')[0].get('alt')
当我得到乳胶方程时它可以工作,但之前的问题有更多部分用双引号引起来。有没有办法得到问题的另一部分,即“什么是价值”。我正在考虑使用正则表达式,但我想看看 Beautiful Soup 是否有可以为我获取它的功能。
【问题讨论】:
标签: python beautifulsoup request