从多个 类 获取值

Getting Values from Multiple Classes

我正在尝试从中获取价格:

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

我正在使用:

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

但是,上面div class中没有的折扣价格,可以通过以下方式找到:

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

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

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

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

结果:

.99
.99
9.00
.99
.99
-2%.98.98
.99
-30%.99.99
.99
-70%.99.99
-10%.99.99
-5%.99.99
-30%.99.99
.99
-10%.99.29
.99
-25%.99.99
.99
.99
.99
.99
.99
-50%.99.99
.99
.99
.99
.99
-66%.99.09
.99
.99
.99
-50%.99.99
-10%.99.99
-40%.99.99
.98
-67%.99.79
-50%.99.99
-30%.99.99
.99
.99
.99
.99
.99
.99
.99
-30%.99.99
.99
-30%.99.99
.99
.99