pyspider--post
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# Created on 2018-08-19 14:47:28
# Project: HBGGZY_SBJ
import json
import pymongo
import hashlib
from bs4 import BeautifulSoup
from pyspider.libs.base_handler import *
class Handler(BaseHandler):
def __init__(self):
self.data = json.dumps({"token":"","pn":0,"rn":10,"sdt":"","edt":"","wd":"","inc_wd":"","exc_wd":"","fields":"title","cnum":"001","sort":"{\"showdate\":\"0\"}","ssort":"title","cl":200,"terminal":"","condition":[{"fieldName":"categorynum","isLike":"true","likeType":2,"equal":"003005"},{"fieldName":"infoc","isLike":"true","likeType":2,"equal":"1300"}],"time":"null","highlights":"title","statistics":"null","unionCondition":"null","accuracy":"","noParticiple":"0","searchRange":"null","isBusiness":1})
self.Client = pymongo.MongoClient()
self.db = self.Client["Tender"]
self.tb = self.db['HBGGZY']
crawl_config = {
}
@every(minutes=15)
def on_start(self):
self.crawl("http://www.hebpr.cn/inteligentsearch/rest/inteligentSearch/getFullTextDataNew",callback=self.index_page,data=self.data,age=60)
@config(age=20 * 24 *60 * 60)
def index_page(self, response):
data = json.loads(response.text)['result']['records']
for item in data:
self.crawl('http://www.hebpr.cn'+item['linkurl'],callback=self.detail_page,save={'title':item['title'],'show_date':item['showdate'],'province':'河北省','city':'省本级','county':item['zhuanzai']})
@config(priority=2)
def detail_page(self, response):
sha1_scripy = hashlib.sha1(response.doc('title').text().encode('utf8'))
sha1_title = sha1_scripy.hexdigest()
data = {
"url": response.url,
"title": response.doc('title').text().encode('utf8'),
"content":str(BeautifulSoup(response.text).find_all("div",id="hideDeil")[0]),
"show_date":response.save["show_date"].split(" ")[0],
"province":response.save["province"],
"city":response.save["city"],
"county":response.save["county"],
"sha1_title":sha1_title,
"is_indb":"0",
"province_id":"130000",
"city_id":"0",
"county_id":"0",
}
MyQuery = self.tb.find({"sha1_title":sha1_title})
if MyQuery.count()>0:
print "存在了"
else:
self.tb.insert(data)
pyspider--post的更多相关文章
- 用pyspider爬淘宝MM照片
#!/usr/bin/env python # -*- encoding: utf-8 -*- # Created on 2016-12-09 15:24:54 # Project: taobaomm ...
- Python爬虫进阶二之PySpider框架安装配置
关于 首先,在此附上项目的地址,以及官方文档 PySpider 官方文档 安装 1. pip 首先确保你已经安装了pip,若没有安装,请参照 pip安装 2. phantomjs PhantomJS ...
- pyspider爬豆瓣电影实例
直接copy官网实例会出现599的错误,百度了很久发现是因为证书的问题 添加这一句忽略证书 validate_cert = False 代码如下: ++++++++++++++++++++++++++ ...
- pyspider 简单应用之快速问医生药品抓取(一)
网址:http://yp.120ask.com/search/-0-0--0-0-0-0.html from pyspider.libs.base_handler import * class Han ...
- Ubuntu下配置Pyspider环境
Ubuntu 14.04.4 LTS 1.ubuntu 系统自带Python 所以不用安装Python 注:安装前先更新下软件源 命令 :sudo apt-get update 2.开始安装pip 命 ...
- pyspider安装
官方文档上说的比较简单: pip install pyspider 但是实际安装时还是有些问题导致无法成功. windows下安装 先安装PhantomJS 可以依照自己的开发平台选择不同的包进行下载 ...
- 安装pyspider
费了三个小时,换了很多版本的Python pip lxml,最终选择安装anaconda2 非常顺利 运行pyspider后localhost:500正常显示 开森
- python3.4学习笔记(十三) 网络爬虫实例代码,使用pyspider抓取多牛投资吧里面的文章信息,抓取政府网新闻内容
python3.4学习笔记(十三) 网络爬虫实例代码,使用pyspider抓取多牛投资吧里面的文章信息PySpider:一个国人编写的强大的网络爬虫系统并带有强大的WebUI,采用Python语言编写 ...
- 【转】CentOS 6.5安装pyspider过程记录
原文地址:http://blog.sina.com.cn/s/blog_48c95a190102wczx.html 1.根据pyspider官方推荐的安装方法,使用pip命令直接安装pyspider ...
- centos安装lxml和pyspider
yum -y install --nogpgcheck python34u-devel.x86_64 yum -y install libcurl-devel yum -y install libxs ...
随机推荐
- jwt 接口加密
什么是JWT Json web token (JWT), 是为了在网络应用环境间传递声明而执行的一种基于JSON的开放标准((RFC 7519).该token被设计为紧凑且安全的,特别适用于分布式站点 ...
- 购物车存到cookie
为什么不存session? 首先,session存在时间限制,会定期清空的,而cookie如果不主动清或者设置定期则不会清楚: session存放在服务器端,cookie存放在客户端浏览器. 购物车存 ...
- python2.7安装beautifulsoup包
python2.7安装beautifulsoup包 准备条件: 1.已经安装好python2.7 2.下载beautifulsoup包,选择合适的包,网址:https://www.crummy.com ...
- 《C语言程序设计》编程总结汇总
<C语言程序设计>编程总结汇总 院系: 专业年级: 班级名称: 学号: 姓名: 指导教师: 完成时间: 自我评价: 计算机科学与技术专业教研室 2018 年秋季学期 第四周编程总结 题目4 ...
- 五分钟带你走入MP
一.MyBatis-Plus简介 1.1MyBatis-Plus是什么? MyBatis-Plus(简称 MP)是一个 MyBatis 的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化 ...
- 内网服务器设置NAT123端口映射,方便外网连接;如何测试端口连通情况。
一.nat123设置端口映射. 1)首先去nat123官网注册账号. http://www.nat123.com/ 2)下载nat123客户端 http://www.nat123.com/Pages_ ...
- best practices for designing web api
restful why: meaningful This will be improve efficiency , less documents , just read the code auto g ...
- C# 利用反射完成计算器可扩展功能
一个主要的窗体程序,两个输入框,一个label using System; using System.Collections.Generic; using System.ComponentModel; ...
- Django学习笔记之数据库-QuerySet_API
QuerySet API 我们通常做查询操作的时候,都是通过模型名字.objects的方式进行操作.其实模型名字.objects是一个django.db.models.manager.Manager对 ...
- Linux 文件查看,文件夹切换,权限查看
当前用户只操作当前用户目录 1. 输入终端显示内容: 用户 @ 系统 : 路径信息 $ $ 表示普通用户 家目录 # 表示超级用户 家目录 [sudo -i ] 使用root用户 : 使用 ...