Python I';我正在抓取具有类似词典的链接。如何区分每本词典?

Python I';我正在抓取具有类似词典的链接。如何区分每本词典?,python,dictionary,Python,Dictionary,我正在从一个二手商品网站上抓取链接,该网站提供了类似的词典。电机相关链接有一种字典类型,带有额外的字典键,我需要其中一个。 其他链接包含所有其他二手商品,并且有一个稍微小一些的字典。 我不知道在这个阶段该做什么。 我曾尝试为与马达相关的字典指定一个名称,名称为'motordict={x:alldata[x]for x in keys1}',但这会由于某些原因导致冲突,可能我的操作方式不对。 我现在很为难,希望能得到任何帮助 字典1。与汽车有关的货物 dict_键(['header'、'descr

我正在从一个二手商品网站上抓取链接,该网站提供了类似的词典。电机相关链接有一种字典类型,带有额外的字典键,我需要其中一个。 其他链接包含所有其他二手商品,并且有一个稍微小一些的字典。 我不知道在这个阶段该做什么。 我曾尝试为与马达相关的字典指定一个名称,名称为'motordict={x:alldata[x]for x in keys1}',但这会由于某些原因导致冲突,可能我的操作方式不对。 我现在很为难,希望能得到任何帮助

字典1。与汽车有关的货物

dict_键(['header'、'description'、'currency'、'price'、'country'、'breadcrumbs'、'displayAttributes'、'views']))

字典2。所有其他二手货

口述键(['header'、'description'、'currency'、'price'、'country'、'breadcrumbs'、'views'])

“导致冲突”是什么意思?不清楚你的目标是什么
x
在您的示例中未定义,因此您应该在示例中硬编码,并减少键的数量,以使其清晰明了。“导致冲突”是什么意思?不清楚你的目标是什么
x
在您的示例中未定义,因此您应该在示例中硬编码,并减少关键点的数量以保持清晰。
 alldata = json.loads(x)
        
        keys2 = ['header', 'breadcrumbs', 'views']

        keys1 = ['header', 'county', 'displayAttributes', 'countyTown', 'breadcrumbs', 'views']

        motordict = {x:alldata[x] for x in keys1}

        views = motordict.get('views')
        title = motordict.get('header')
        county = motordict.get('county')
        countyTown = motordict.get('countyTown')
        itemId = motordict.get('id')
        sellerId = motordict.get('seller')['id']
        sellerName = motordict.get('seller')['name']
        adCount = motordict.get('seller')['adCount']
        lifetimeAds = motordict.get('seller')['adCountStats']['lifetimeAdView']['value']
        currency = motordict.get('currency')
        price = motordict.get('price')
        adUrl = motordict.get('friendlyUrl')
        adAge = motordict.get('age')
        spotlight = motordict.get('spotlight')