爬虫实例1-爬取新闻列表和发布时间
2017-06-19 20:43
211 查看
一、新建工程
二、Items.py文件代码:
三、shopspider.py文件爬虫代码
四、pipelines.py文件代码(打印出内容):注意:如果在shopspider.py文件中打印出内容则显示的是unicode编码,而在pipelines.py打印出来的信息则是正常的显示内容。
五、爬取显示的结果:
scrapy startproject shop |
import scrapy class ShopItem(scrapy.Item): title = scrapy.Field() time = scrapy.Field() |
# -*-coding:UTF-8-*-import scrapyfrom shop.items import ShopItem class shopSpider(scrapy.Spider): name = "shop" allowed_domains = ["news.xxxxxxx.xx.cn"] start_urls = ["http://news.xxxxx.xxx.cn/hunan/"] def parse(self,response):item = ShopItem()item['title'] = response.xpath("//div[@class='txttotwe2']/ul/li/a/text()").extract()item['time'] = response.xpath("//div[@class='txttotwe2']/ul/li/font/text()").extract()yield item |
class ShopPipeline(object): def process_item(self, item, spider): count=len(item['title']) print 'news count: ' ,count for i in range(0,count): print 'biaoti: '+item['title'][i] print 'shijian: '+item['time'][i] return item |
root@kali:~/shop# scrapy crawl shop --nolognews count: 40biaoti: xxx建成国家食品安全示范城市shijian: (2017-06-16)biaoti: xxxx考试开始报名…………………… ………………….. |
相关文章推荐
- 基于时间的访问控制列表配置实例
- 经典!!!一个新闻发布网站实例
- Android基础入门教程——5.2.5 Fragment实例精讲——新闻(购物)类App列表Fragment的简单实现
- Fragment实例精讲——新闻(购物)类App列表Fragment的简单实现
- 基于JS实现新闻列表无缝向上滚动实例代码
- DWR 应用实例(二) 新闻发布系统,多种新闻类型之间切换无刷新
- 织梦dedecms TAG列表按最新发布时间排序的解决方法
- PHP实现简单的新闻发布系统实例
- python3.4学习笔记(十三) 网络爬虫实例代码,使用pyspider抓取多牛投资吧里面的文章信息,抓取政府网新闻内容
- 使用 Jsoup 爬虫解析 html 新闻的实例
- dl,dt,dd实现新闻列表的一个实例
- 编写新闻发布系统 显示新闻条目时间问题
- PHP框架Yii实例学习(新闻发布系统2)
- PHP实现简单的新闻发布系统实例
- JAVA_WEB项目(结合Servlet+jsp+ckEditor编辑器+jquery easyui技术)实现新闻发布管理系统第四篇:前台首页,新闻分类(体育新闻,科技新闻等),新闻列表分页的实现
- 帝国网站管理系统v5.0发布时间及已完成功能列表
- PHP框架YII实例学习(新闻发布系统1)
- 新闻列表设计 时间+标题
- 发布自己写的一个简单的新闻列表WebPart
- O365(世纪互联)SharePoint 之使用列表库发布新闻