爬取网页菜谱

爬取网页菜谱:
http://www.xiachufang.com/explore/

import requests as req
from bs4 import BeautifulSoup

path='http://www.xiachufang.com/explore/'
raw=req.get(path)
trans=BeautifulSoup(raw.text,'html.parser')
cai_lists=trans.find_all('p',class_='name')
#url_lists=cai_lists.find_all('a').children
#print(cai_lists)
#print(url_lists)
ingredient_lists=trans.find_all('p',class_='ing ellipsis')

list_temp=[]
list_total=[]
for i in range(len(cai_lists)):
    list_temp=[]
    cai=cai_lists[i]
    name=cai.text[18:-14]
    address='http://www.xiachufang.com'+str(cai.find('a')["href"])
    recipe=ingredient_lists[i]
    list_temp.append(cai)
    list_temp.append(address)
    list_temp.append(recipe)
    list_total.append(list_temp)
print(list_total[1])

你可能感兴趣的:(爬取网页菜谱)