Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如果标签存在,那么查找很好_Python_Web Scraping_Beautifulsoup - Fatal编程技术网

Python 如果标签存在,那么查找很好

Python 如果标签存在,那么查找很好,python,web-scraping,beautifulsoup,Python,Web Scraping,Beautifulsoup,我一直在尝试使用BeautifulSoup来找出这个代码。我希望它做什么,因为我正在拉各种页面,它们没有一致的标记,如果它找到一个标记来运行该代码,如果它找到另一个标记来运行另一个代码,但我到目前为止还没有成功,我希望得到一些帮助: 我没有收到任何错误消息,我不知道循环是否中断或只是跳过它,但它没有打印任何内容 网址如下: 我的密码是: for price in pricing: if pricing.find('discount_final_price'):

我一直在尝试使用BeautifulSoup来找出这个代码。我希望它做什么,因为我正在拉各种页面,它们没有一致的标记,如果它找到一个标记来运行该代码,如果它找到另一个标记来运行另一个代码,但我到目前为止还没有成功,我希望得到一些帮助:

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

网址如下:

  • 我的密码是:

    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)
    

    嗨,我不知道price变量中有什么,但这段代码运行良好:

    for price in pricing:
    
        game_price = soup.find('div', class_='discount_final_price')
    
        if game_price != None :
            print( "Price : {}".format(game_price.text) )
    
        else :
            game_price = pricing.find('div', class_='game_purchase_price price')
            print( "Price : {}".format(game_price.text) )
    

    你收到错误信息了吗?始终将完整的错误消息(回溯)放在问题中(作为文本,而不是屏幕截图)。还有其他有用的信息。把url放在问题中(不在评论中),这样我们就可以检查HTML中的标记。两个页面都要求先输入“出生日期”。也许他们会把它保存在饼干里。你可能需要这个coockie当你试图获得价格页面。如果使用
    请求
    ,则可以轻松设置此cookie。但首先你必须在浏览器中找到它。@furas啊,我知道了,我会看看我是否能找到它,谢谢你在GTA中设置出生日期后,我看到cookie
    生日:-2208989360
    。如果我移除它,它会再次询问出生日期。