发生了什么事?
认为这不是 request 与 selenium 的网络抓取问题,因为您所做的只是请求 api 并获得 json 响应。
而且您的代码按照编写的方式运行良好,但您期望做的是其他事情,因此您必须以另一种方式处理迭代 dict。
这样就可以了:
page['data']['menu']['items'].items()
示例
import requests
url = 'https://www.swiggy.com/dapi/menu/v4/full?lat=12.9715987&lng=77.5945627&menuId=41100'
page = requests.get(url).json()
for k, v in page['data']['menu']['items'].items():
print(v)
输出
{'id': 8194821, 'name': 'Egg Omelette', 'category': 'Quick Bites', 'description': '', 'cloudinaryImageId': '', 'recommended': 0, 'inStock': 0, 'isVeg': 0, 'enabled': 1, 'displayOrder': 0, 'price': 8500, 'variants_new': {'exclude_list': [], 'variant_groups': []}, 'addons': [{'group_id': 21778839, 'group_name': 'Addons', 'choices': [{'id': 17471659, 'name': 'Watermelon Juice', 'price': 10000, 'inStock': 0, 'isVeg': 1, 'order': 1, 'default': 0}, {'id': 17471658, 'name': 'Coke (750 ml)', 'price': 6000, 'inStock': 1, 'isVeg': 1, 'order': 1, 'default': 0}], 'maxAddons': -1, 'maxFreeAddons': -1, 'minAddons': 0, 'order': 1}, {'group_id': 21778838, 'group_name': 'Beverage Addons', 'choices': [{'id': 17471658, 'name': 'Coke (750 ml)', 'price': 6000, 'inStock': 1, 'isVeg': 1, 'order': 1, 'default': 0}], 'maxAddons': -1, 'maxFreeAddons': -1, 'minAddons': 0, 'order': 1}], 'cropChoices': 2, 'itemScore': 0, 'itemDiscount': 0, 'isPopular': 0, 'restId': '41100', 'showMC': 0, 'ribbon': {'text': 'Must Try', 'textColor': '#ffffff', 'topBackgroundColor': '#d53d4c', 'bottomBackgroundColor': '#b02331'}, 'attributes': {'portionSize': '', 'vegClassifier': 'EGG', 'accompaniments': ''}, 'itemNudgeType': ''}
{'id': 8194822, 'name': 'Paneer Sholey', 'category': 'Starters', 'description': 'Fried cottage cheese cubes, tossed in signature spices & curry leaves garnish.', 'cloudinaryImageId': '', 'recommended': 0, 'inStock': 0, 'isVeg': 1, 'enabled': 1, 'displayOrder': 0, 'price': 22000, 'variants_new': {'exclude_list': [], 'variant_groups': []}, 'cropChoices': 2, 'itemScore': 0, 'itemDiscount': 0, 'isPopular': 0, 'restId': '41100', 'showMC': 0, 'attributes': {'portionSize': '', 'vegClassifier': 'VEG', 'accompaniments': ''}, 'itemNudgeType': ''}
...