123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- # -*- coding: utf-8 -*-
- """
- Created on 2024-12-12
- ---------
- @summary: 中国建设银行集采平台
- ---------
- @author: lzz
- """
- from collections import namedtuple
- import feapder
- from items.spider_item import BidingListItem
- class Spider(feapder.BiddingListSpider):
- def start_callback(self):
- Menu = namedtuple('Menu', ['channel', 'code', 'tid', 'crawl_page'])
- self.site = "中国建设银行集采平台"
- self.menus = [
- Menu('采购专区-变更公告', 'a_zgjsyhjcpt_cgzq_bggg', '357', 1),
- ]
- self.headers = {
- "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
- "Accept-Language": "zh-CN,zh;q=0.9",
- "Cache-Control": "max-age=0",
- # "Connection": "keep-alive",
- "Content-Type": "application/x-www-form-urlencoded",
- "Origin": "https://ibuy.ccb.com",
- "Referer": "https://ibuy.ccb.com/cms/channel/ccbbidzbgg/index.htm",
- "Upgrade-Insecure-Requests": "1",
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36",
- }
- def start_requests(self):
- for menu in self.menus:
- url = f"https://ibuy.ccb.com/json/contentFile/{menu.tid}/1.json"
- yield feapder.Request(url, item=menu._asdict(), page=1)
- def download_midware(self, request):
- request.headers = self.headers
- def parse(self, request, response):
- menu = request.item
- info_list = response.json
- for info in info_list:
- title = info.get('title').strip()
- hid = info.get('id')
- pid = menu.get('tid')
- href = f"https://ibuy.ccb.com/cms/index.html#/content?pId={pid}&id={hid}"
- create_time = info.get('releaseDate').strip()
- htm = create_time.split('-')[0]
- area = "全国" # 省份
- city = "" # 城市
- list_item = BidingListItem() # 存储数据的管道
- list_item.href = href # 标书链接
- list_item.channel = menu.get("channel") # 最上方定义的抓取栏目 (编辑器定的)
- list_item.spidercode = menu.get("code") # 最上方定义的爬虫code(编辑器定的)
- list_item.title = title # 标题
- list_item.publishtime = create_time # 标书发布时间
- list_item.site = self.site
- list_item.area = area # 城市默认:全国
- list_item.city = city # 城市 默认为空
- list_item.unique_key = ('href',)
- list_item.parse = "self.detail_get" # 详情页回调方法
- list_item.parse_url = f"https://ibuy.ccb.com/json/contentFile/{pid}/{htm}/{hid}.json"
- yield list_item
- # 无限翻页
- request = self.infinite_pages(request, response)
- yield request
- if __name__ == "__main__":
- Spider(redis_key="lzz:Zgjsyhjcpt").start()
|