您好,欢迎来到星星旅游。
搜索
您的当前位置:首页python-python爬取豆果网(菜谱信息)

python-python爬取豆果网(菜谱信息)

来源:星星旅游

#-*- coding = utf-8 -*-
#获取豆果网图片
import io
from bs4 import BeautifulSoup
import requests

#爬取菜谱的地址
url = "https://www.douguo.com/cookbook/20292.html"
#防止网址的反爬虫
header = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW; rv:23.0) Gecko/20100101 Firefox/23.0'}
#获取网页信息
html = requests.get(url,headers = header)
#解析网页信息
text = BeautifulSoup(html.content,"lxml")
#获取主要菜谱图片的地址(在此仅仅获取了一张图片)
img_title = text.select("#banner img")
imgg = img_title[0].get("src")
#根据url将图片保存到当地
def get_img_data(ul):
    htm = requests.get(ul,headers = header)
    filename = "1.jpg"
    #这个地方的filename可以根据需求进行修改
    f =  open(filename,"wb")
    #将图片写到文件中
    f.write(htm.content)
    f.close()
get_img_data(imgg)

#分别获取菜谱信息
menu_title_0 = text.select('.title.text-lips')[0].text
menu_intro   = text.select('.intro')[0].text
menu_title_1 = text.select('.mini-title')[0].text
menu_content_scname = text.find_all('span',class_='scname')
menu_content_scnum = text.find_all('span',class_='scnum')
menu_title_2 = text.select('.mini-title')[1].text
menu_step = text.select('.stepinfo')

print(menu_title_0)
print(menu_intro)
print(menu_title_1)
count = 0
for i in menu_content_scname:
    print(i.text," ",menu_content_scnum[count].text)
    count = count + 1
print(menu_title_2)
for menu_step_i in menu_step:
    print(menu_step_i.text)

 

 

posted @ 2019-01-22 21:10 阅读( ...) 评论( ...)

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- stra.cn 版权所有 赣ICP备2024042791号-4

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务