python - 网页抓取结果为无
问题描述
我很难从 Nordstrom 网站上提取以下产品价格。
<div class="_1vV3F"><section id="product-page-price-lockup" class=""><span><span class="_1k-6h _30Yxg">Price</span><span id="current-price-string" class="_1ds4c">$745.00</span>
这是我的代码的一部分:
soup1 = BeautifulSoup(page.content, "html.parser")
soup2 = BeautifulSoup(soup1.prettify(), "html.parser")
price = soup2.find(class_ = "_1ds4c")
print(price)
解决方案
选择方式id=
:
txt = '''<div class="_1vV3F"><section id="product-page-price-lockup" class=""><span><span class="_1k-6h _30Yxg">Price</span><span id="current-price-string" class="_1ds4c">$745.00</span>'''
soup = BeautifulSoup(txt, 'html.parser')
print(soup.select_one('#current-price-string').text)
印刷:
$745.00
或者:
print(soup.find(id='current-price-string').text)
印刷:
$745.00
推荐阅读
- php - 如何在 Laravel 中通过电子邮件发送 HTML 格式
- sql - 返回未终止 PL/SQL 过程的管理器的 Oracle 查询
- python - Scipy SLSQP 约束优化并不总是有效
- sqlite - 我怎样才能得到这个 sqlite 查询的结果?
- java - Java DAO 设计 - 返回 MAP 而不是 POJO
- python - 在 Python 中将对象标记为已删除
- javascript - 通过遍历数组来制作对象属性 - JS
- apache-spark - Spark Streams:状态使用
- angular - 在 Angular 应用程序中无法访问资产文件夹中的图像
- python - Pandas:根据另一列的值将列拆分为较小的列