我正在尝试编写一个检查 Steam 商店的脚本,但在过滤掉代码中没有折扣的所有列表时遇到问题。我只想保留带有 span 标签的列表以及<span>-percentage</span>其中的列表,而不是没有的列表。这是我的代码:
from urllib.request import urlopen
from datetime import date
import requests as rq
inp = str(input('what would you like to search up?'))
w = ('https://store.steampowered.com/search/?term=' + inp)
page = rq.get(w)
soup = bsoup(page.content, 'html.parser')
soup.prettify()
sales = soup.find_all('div', class_="responsive_search_name_combined")
for sale in sales:
p = soup.find('div', class_="col search_price responsive_secondrow")
d = soup.find_all('div', class_="col search_discount responsive_secondrow")
n = soup.find('span', class_="title")
if None in (d, n, p):
continue
print(d)
和输出(包含我想要过滤掉的东西/我想要保留的东西)
<span>-16%</span>
</div>, <div class="col search_discount responsive_secondrow">
</div>, <div class="col search_discount responsive_secondrow">
<span>-19%</span>
</div>, <div class="col search_discount responsive_secondrow">
</div>, <div class="col search_discount responsive_secondrow">
</div>, <div class="col search_discount responsive_secondrow">
</div>, <div class="col search_discount responsive_secondrow">
</div>, <div class="col search_discount responsive_secondrow">
</div>, <div class="col search_discount responsive_secondrow">
</div>, <div class="col search_discount responsive_secondrow">
</div>, <div class="col search_discount responsive_secondrow">
</div>, <div class="col search_discount responsive_secondrow">
</div>, <div class="col search_discount responsive_secondrow">
</div>, <div class="col search_discount responsive_secondrow">
</div>, <div class="col search_discount responsive_secondrow">
</div>, <div class="col search_discount responsive_secondrow">
</div>, <div class="col search_discount responsive_secondrow">
</div>, <div class="col search_discount responsive_secondrow">
等等,我尝试替换d = soup.find_all('div', class_="col search_discount responsive_secondrow")为,d = soup.find_all('span', string="-16%")看看是否有效,但没有。我想保留 span 标签,但不保留 div 标签,有人可以帮忙吗?
哈士奇WWW
相关分类