网页抓取结果为无

时间:2020-06-11 21:50:45

标签: python web-scraping

我很难从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)

1 个答案:

答案 0 :(得分:0)

通过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