【问题标题】:Getting Values from Multiple Classes从多个类中获取值
【发布时间】:2023-04-08 23:43:02
【问题描述】:

我正在尝试从以下位置获取价格:

https://store.steampowered.com/search/?filter=topsellers&snr=1_241_4_action_12

我正在使用:

soup.find_all('div',{'class':'col search_price responsive_secondrow'})

但是,上面的 div 类中没有折扣价格,而是可以使用以下命令找到它们:

soup.find_all('div',{'class':'col search_price discounted responsive_secondrow'})

我已经抓取了游戏的标题,并且希望价格也对应在同一行,那么如何完成合并两个抓取条件?

【问题讨论】:

    标签: python html web-scraping beautifulsoup list-comprehension


    【解决方案1】:

    您可以改用它的父元素,它包含两个价格。

    for i in soup.find_all('div',{'class':"col search_price_discount_combined responsive_secondrow"}):
        print(i.text.replace("\n","").strip())
    

    结果:

    $49.99
    $59.99
    $999.00
    $59.99
    $59.99
    -2%$89.98$87.98
    $19.99
    -30%$59.99$41.99
    $59.99
    -70%$59.99$17.99
    -10%$29.99$26.99
    -5%$39.99$37.99
    -30%$29.99$20.99
    $29.99
    -10%$16.99$15.29
    $19.99
    -25%$19.99$14.99
    $13.99
    $99.99
    $14.99
    $59.99
    $19.99
    -50%$9.99$4.99
    $59.99
    $39.99
    $59.99
    $59.99
    -66%$14.99$5.09
    $39.99
    $49.99
    $39.99
    -50%$59.99$29.99
    -10%$29.99$26.99
    -40%$59.99$35.99
    $29.98
    -67%$59.99$19.79
    -50%$29.99$14.99
    -30%$19.99$13.99
    $2.99
    $2.99
    $2.99
    $2.99
    $2.99
    $2.99
    $14.99
    -30%$59.99$41.99
    $44.99
    -30%$59.99$41.99
    $59.99
    $59.99
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-19
      • 1970-01-01
      • 2011-09-20
      • 2015-01-09
      相关资源
      最近更新 更多