Scrapy项目_阳光热线问政平台
目的:
爬取阳光热线问政平台问题中每个帖子的标题、详情URL、详情内容、图片以及发布时间


步骤:
1、创建爬虫项目
1 scrapy startproject yangguang
2 cd yangguang
3 scrapy genspider yangguang sun0769.com
2、设置item.py文件
import scrapy class YangguangItem(scrapy.Item):
# 每条帖子的标题
title = scrapy.Field()
# 帖子链接
href = scrapy.Field()
# 发布日期
publish_time = scrapy.Field()
# 详情内容
content = scrapy.Field()
# 详情图片
content_img = scrapy.Field()
3、编写爬虫文件
1 import scrapy
2 from yangguang.items import YangguangItem
3
4
5 class YgSpider(scrapy.Spider):
6 name = 'yg'
7 allowed_domains = ['sun0769.com']
8 start_urls = ['http://wz.sun0769.com/political/index/politicsNewest?id=1&page=1']
9
10 page = 1
11 url = "http://wz.sun0769.com/political/index/politicsNewest?id=1&page= {}"
12
13 def parse(self, response):
14 # 分组
15 li_list = response.xpath("//ul[@class='title-state-ul']/li")
16 for li in li_list:
17 item = YangguangItem()
18 item["title"] = li.xpath("./span[@class='state3']/a/text()").extract_first()
19 item["href"] = "http://wz.sun0769.com" + li.xpath("./span[@class='state3']/a/@href").extract_first()
20 item["publish_time"] = li.xpath("./span[@class='state5 ']/text()").extract_first()
21
22 yield scrapy.Request(
23 item["href"],
24 callback=self.parse_detail,
25 meta={
26 "item": item,
27 "proxy": "http://171.12.221.51:9999"
28 }
29 )
30 # 翻页
31 if self.page < 10:
32 self.page += 1
33 next_url = self.url.format(self.page)
34
35 yield scrapy.Request(next_url, callback=self.parse, meta={"proxy": "http://123.163.118.71:9999"})
36
37 def parse_detail(self, response): # 处理详情页
38 item = response.meta["item"]
39 item["content"] = response.xpath("//div[@class='details-box']/pre/text()").extract_first()
40 item["content_img"] = response.xpath("//div[@class='clear details-img-list Picture-img']/img/@src").extract()
41 yield item
4、测试
scrapy crawl yg

Scrapy项目_阳光热线问政平台的更多相关文章
- scrapy爬虫案例--爬取阳关热线问政平台
阳光热线问政平台:http://wz.sun0769.com/political/index/politicsNewest?id=1&page=1 爬取最新问政帖子的编号.投诉标题.投诉内容以 ...
- Scrapy项目_苏宁图书信息
苏宁图书(https://book.suning.com/) 目标: 1.图书一级分类 2.图书二级分类 3.图书三级分类 4.图书名字 5.图书作者 6.图书价格 7.通过Scrapy获取以上数据 ...
- 爬虫——Scrapy框架案例二:阳光问政平台
阳光热线问政平台 URL地址:http://wz.sun0769.com/index.php/question/questionType?type=4&page= 爬取字段:帖子的编号.投诉类 ...
- scrapy爬虫案例:问政平台
问政平台 http://wz.sun0769.com/index.php/question/questionType?type=4 爬取投诉帖子的编号.帖子的url.帖子的标题,和帖子里的内容. it ...
- C++框架_之Qt的开始部分_概述_安装_创建项目_快捷键等一系列注意细节
C++框架_之Qt的开始部分_概述_安装_创建项目_快捷键等一系列注意细节 1.Qt概述 1.1 什么是Qt Qt是一个跨平台的C++图形用户界面应用程序框架.它为应用程序开发者提供建立艺术级图形界面 ...
- python爬虫scrapy项目详解(关注、持续更新)
python爬虫scrapy项目(一) 爬取目标:腾讯招聘网站(起始url:https://hr.tencent.com/position.php?keywords=&tid=0&st ...
- 亲测——pycharm下运行第一个scrapy项目 ©seven_clear
最近在学习scrapy,就想着用pycharm调试,但不知道怎么弄,从网上搜了很多方法,这里总结一个我试成功了的. 首先当然是安装scrapy,安装教程什么的网上一大堆,这里推荐一个详细的:http: ...
- 凡客副总裁崔晓琦离职 曾负责旗下V+商城项目_科技_腾讯网
凡客副总裁崔晓琦离职 曾负责旗下V+商城项目_科技_腾讯网 凡客副总裁崔晓琦离职 曾负责旗下V+商城项目 腾讯科技[微博]乐天2013年09月18日12:44 分享 微博 空间 微信 新浪微博 邮箱 ...
- scrapy(一)建立一个scrapy项目
本项目实现了获取stack overflow的问题,语言使用python,框架scrapy框架,选取mongoDB作为持久化数据库,redis做为数据缓存 项目源码可以参考我的github:https ...
随机推荐
- K8s 一、(1、容器基本概念 2、k8s基本概念 )
1.容器基本概念 容器其实就是一种特殊的进程,容器是一个 '单进程'模型. Namespace :隔离 Namespace 技术实际上修改了应用进程看待整个计算机"视图",即它的& ...
- EIGRP和OSPF__邻居发现
散知识点 1.当配置通配符时,它们的取值总是块尺寸减去1:/28的块尺寸为16,因此当我们添加网络声明时,使用了此子网号和一个在需配置的八位位组中添加值为15的通配符. 邻居发现 1.在EIGRP路由 ...
- 【xml】控件常用属性
https://www.cnblogs.com/xqz0618/p/textview.html (常用,生动) https://www.jianshu.com/p/992324336dd9 (全,简洁 ...
- Python爬虫笔记一(来自MOOC) Requests库入门
Python爬虫笔记一(来自MOOC) 提示:本文是我在中国大学MOOC里面自学以及敲的一部分代码,纯一个记录文,如果刚好有人也是看的这个课,方便搬运在自己电脑上运行. 课程为:北京理工大学-嵩天-P ...
- Scala集合库、模式匹配和样例类
package com.yz8 import org.junit.Test class test { @Test def test: Unit = { val ints = List(1,5,7,6, ...
- [CF套题] CF-1201
CF-1201 传送门 # = * A 500 B 1000 C 1500 D 2000 E1 2000 E2 1000 1 (2217) 1672 482 00:09 400 01:40 790 0 ...
- HDU4358 Boring counting【dsu on tree】
Boring counting Problem Description In this problem we consider a rooted tree with N vertices. The v ...
- python爬取网易翻译 和MD5加密
一.程序需要知识 1.python中随机数的生成 # 生成 0 ~ 9 之间的随机数 # 导入 random(随机数) 模块 import random print(random.randint(0, ...
- hdu1828 Picture(线段树+扫描线+矩形周长)
看这篇博客前可以看一下扫描线求面积:线段树扫描线(一.Atlantis HDU - 1542(覆盖面积) 二.覆盖的面积 HDU - 1255(重叠两次的面积)) 解法一·:两次扫描线 如图我们可以 ...
- hdu5375 Gray code
Problem Description The reflected binary code, also known as Gray code after Frank Gray, is a binary ...