我正试着从一个webpage中找出不同的食谱。到目前为止,我所写的内容可以解析所有配方名称。然而,我找不到任何方法来访问单个配方链接。以下是每个容器的外观,其中没有可用的slug,因此我找不到任何关于如何访问不同配方的内部页面的线索:
{'id': 748,
'img': 'https://cdn-uploads.mealime.com/uploads/recipe/thumbnail/41/thumbnail_708f7645-6cb4-4089-8e18-95f5b97cbbcf.jpg',
'name': 'Apple Quinoa Salad with Celery, Almonds & Dried Cranberries',
'recipeId': 41,
'restrictions': [6],
'types': [1, 3, 2, 4]}
如果我没有错的话,这是https://www.mealime.com/_next/data/kSmAjTn7MJl4zVPNE6MeR/recipes/greek-turkey-meatball-pita-wraps-veggies-olives-feta-sauce/14887.json
一个单独的配方链接应该是什么样子的,它会引导到内部页面
我试过:
import requests
from pprint import pprint
link = 'https://www.mealime.com/_next/data/kSmAjTn7MJl4zVPNE6MeR/recipes.json'
with requests.Session() as s:
s.headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36'
res = s.get(link)
for item in res.json()['pageProps']['reducedVariants']:
pprint(item)
How can I access to the inner page of individual recipe derived from json response?
在这里,我已经为一个您可以用于所有的应用做了准备,但是
name
可以包含必须删除的不必要的单词,然后我们可以再次发出请求,您可以获得所需的输出:输出:
相关问题 更多 >
编程相关推荐