【问题标题】:Web scrape results in None网页抓取结果为无
【发布时间】:2020-06-12 05:59:58
【问题描述】:

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

【问题讨论】:

    标签: python web-scraping


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2016-07-23
      • 2015-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-23
      • 2017-09-24
      • 1970-01-01
      相关资源
      最近更新 更多