小编IoH*_*IoH的帖子

Beautiful Soup 查找标签是否存在

我一直在尝试使用 Beautiful Soup 来找出这段代码。我想要它做什么,因为我正在拉各种页面并且它们没有一致的标签,如果它找到一个标签来运行该代码,如果它找到另一个标签来运行另一个代码,但我没有成功所以到目前为止,我很感激一些帮助:

我没有收到任何错误消息,我不知道循环是否中断,或者它是否只是跳过它但它没有打印任何内容。

网址是:

  1. http://store.steampowered.com/app/271590/Grand_Theft_Auto_V/

  2. http://store.steampowered.com/app/578080/PLAYERUNKNOWNS_BATTLEGROUNDS/

我的代码是:

for price in pricing:

        if pricing.find('discount_final_price'):
            game_price = price.find('discount_final_price')
            gamprice = game_price[i].text
            print("Price:" + gamprice)  
        else :
            game_price = price.find("game_purchase_price price")
            gamprice = game_price[i].text
            print("Price:" + gamprice)
Run Code Online (Sandbox Code Playgroud)

python beautifulsoup web-scraping

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

beautifulsoup ×1

python ×1

web-scraping ×1