【发布时间】:2021-02-23 14:55:53
【问题描述】:
如何从下面的 HTML 代码中提取值“1.00 TK = 779.8”?
我尝试了下面的代码,但它不起作用;
from bs4 import BeautifulSoup
page = requests.get(<url>).text
##here is the html page content'''<span _ngcontent-his-c101="" id="driveValue" class="ng-binding ng-scope"> 1.00 TK = 779.8<span _ngcontent-his-c101="">Disk Drive Value</span>(DDV) </span>'''
soup = BeautifulSoup(html, 'html.parser')
print(soup.find(id='driveValue').find_next(text=True).strip())
错误:
AttributeError: 'NoneType' object has no attribute 'find_next'
【问题讨论】:
-
我尝试使用 id="driveValue" 提取值,结果没有
标签: python html css web-scraping beautifulsoup