#!/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的更多相关文章

  1. 用pyspider爬淘宝MM照片

    #!/usr/bin/env python # -*- encoding: utf-8 -*- # Created on 2016-12-09 15:24:54 # Project: taobaomm ...

  2. Python爬虫进阶二之PySpider框架安装配置

    关于 首先,在此附上项目的地址,以及官方文档 PySpider 官方文档 安装 1. pip 首先确保你已经安装了pip,若没有安装,请参照 pip安装 2. phantomjs PhantomJS ...

  3. pyspider爬豆瓣电影实例

    直接copy官网实例会出现599的错误,百度了很久发现是因为证书的问题 添加这一句忽略证书 validate_cert = False 代码如下: ++++++++++++++++++++++++++ ...

  4. pyspider 简单应用之快速问医生药品抓取(一)

    网址:http://yp.120ask.com/search/-0-0--0-0-0-0.html from pyspider.libs.base_handler import * class Han ...

  5. Ubuntu下配置Pyspider环境

    Ubuntu 14.04.4 LTS 1.ubuntu 系统自带Python 所以不用安装Python 注:安装前先更新下软件源 命令 :sudo apt-get update 2.开始安装pip 命 ...

  6. pyspider安装

    官方文档上说的比较简单: pip install pyspider 但是实际安装时还是有些问题导致无法成功. windows下安装 先安装PhantomJS 可以依照自己的开发平台选择不同的包进行下载 ...

  7. 安装pyspider

    费了三个小时,换了很多版本的Python pip lxml,最终选择安装anaconda2 非常顺利 运行pyspider后localhost:500正常显示 开森

  8. python3.4学习笔记(十三) 网络爬虫实例代码,使用pyspider抓取多牛投资吧里面的文章信息,抓取政府网新闻内容

    python3.4学习笔记(十三) 网络爬虫实例代码,使用pyspider抓取多牛投资吧里面的文章信息PySpider:一个国人编写的强大的网络爬虫系统并带有强大的WebUI,采用Python语言编写 ...

  9. 【转】CentOS 6.5安装pyspider过程记录

    原文地址:http://blog.sina.com.cn/s/blog_48c95a190102wczx.html 1.根据pyspider官方推荐的安装方法,使用pip命令直接安装pyspider ...

  10. centos安装lxml和pyspider

    yum -y install --nogpgcheck python34u-devel.x86_64 yum -y install libcurl-devel yum -y install libxs ...

随机推荐

  1. dp——完全背包(方案数)

    Problem J. icebound 的商店Time limit: 1000msMemory limit: 65536KBDescriptionicebound 在得到神殿的宝藏之后,开了一家神秘的 ...

  2. java-Set集合、HashSet集合、LinkedHashSet集合和TreeSet集合

    1.Set集合,无索引,不可以重复,无序(存取不一致) public class Demo { public static void main(String[] args) { //demo1(); ...

  3. 无状态http协议上用户的身份认证

    1.注册时可以使用手机短信验证码进行身份认证 2.用户每次请求不能每次都发送验证码,这时需要服务器给客户端颁发一个身份凭证(一般为一个唯一的随机数),用户每次请求时都携带身份凭证, 服务器会记录该身份 ...

  4. c#利用ApplicationContext类 同时启动双窗体的实现

    Application类(位于System.Windows.Forms命名空间)公开了Run方法,可以调用该方法来调度应用程序进入消息循环.Run方法有三个重载 1.第一个重载版本不带任何参数,比较少 ...

  5. zabbix自动发现zabbix_agent后添加到所属组和链接到某些模块(九)

    自动发现的两个操作:discovery(自动发现) and actions(发现后执行某个操作)   需求:   1:自动发现 Zabbix agent运行的主机   2:执行的动作 1)添加到所属组 ...

  6. Fabric的settings用法

    http://fabric-chs.readthedocs.io/zh_CN/chs/api/core/context_managers.html?highlight=with%20settings# ...

  7. ID的故事

    随心所欲.这个时代比较中二吧,刚出国,也买了房,年纪轻轻的觉得自己好像很牛B的样子. 失败悲观的路人甲.大约是13年的时候,突遭重击,一下子悲观失望,死的心都有.为此买了那种自杀也会给赔偿的保险(买后 ...

  8. ClientDataSet

    TField对象的SetText和GetText事件处理函数 使用TField对象的SetText和GetText事件处理函数可方便的解决字段的代码与代码所对应值的显示问题 TSimpleDatase ...

  9. xterm下字体设置

    code ~/.Xdefaults xterm*locale: true xterm.utf8: true xterm*utf8Title: true ! 滚动条 !XTerm*scrollBar: ...

  10. python虚拟环境virtualenv简介

    参考网站: https://realpython.com/python-virtual-environments-a-primer/ 一. 创建一个新的虚拟环境 # Python 2: $ virtu ...