本文主要是介绍Scrapy爬虫爬取天气数据存储为txt和json等多种格式,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一、创建Scrrapy项目
scrapy startproject weather
二、 创建爬虫文件
scrapy genspider wuhanSpider wuhan.tianqi.com
三、SCrapy项目各个文件
(1) items.py
import scrapyclass WeatherItem(scrapy.Item):# define the fields for your item here like:# name = scrapy.Field()cityDate = scrapy.Field()week = scrapy.Field()img = scrapy.Field()temperature = scrapy.Field()weather = scrapy.Field()wind = scrapy.Field()
(2)wuhanSpider.py
# -*- coding: utf-8 -*-
import scrapy
from weather.items import WeatherItemclass WuhanspiderSpider(scrapy.Spider):name = "wuHanSpider"allowed_domains = ["tianqi.com"]citys = [&
这篇关于Scrapy爬虫爬取天气数据存储为txt和json等多种格式的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!