招标计划-列表页.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on 2025-04-05
  4. ---------
  5. @summary: 广东省招投标监管网
  6. ---------
  7. @author: lzz
  8. """
  9. import feapder
  10. from items.spider_item import BidingListItem
  11. from collections import namedtuple
  12. from ztbjgw_tool import *
  13. import json
  14. class ZtbpcFeapder(feapder.BiddingListSpider):
  15. def start_callback(self):
  16. self.site = "广东省招投标监管网"
  17. Menu = namedtuple('Menu', ['channel', 'code', 'crawl_page'])
  18. self.menus = [
  19. Menu('招标计划', 'gd_gdsztbjgw_zbjh', 1),
  20. ]
  21. self.headers = {
  22. 'Accept': 'application/json, text/plain, */*',
  23. 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,sq;q=0.7',
  24. 'Cache-Control': 'no-cache',
  25. 'Connection': 'keep-alive',
  26. 'Content-Type': 'application/json',
  27. 'Origin': 'https://zbtb.gd.gov.cn',
  28. 'Pragma': 'no-cache',
  29. 'Referer': 'https://zbtb.gd.gov.cn/',
  30. 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
  31. }
  32. def start_requests(self):
  33. for menu in self.menus:
  34. start_url = "https://zbtb.gd.gov.cn/ztbjg-portal/center/notice/search"
  35. yield feapder.Request(url=start_url, item=menu._asdict(), page=1, proxies=False)
  36. def validate(self, request, response):
  37. data = response.json.get('data')
  38. if not data:
  39. raise ValueError(f"data is '{data}'")
  40. return True
  41. def download_midware(self, request):
  42. page = request.page
  43. data = {
  44. "type": "trading-type",
  45. "publishStartTime": "",
  46. "publishEndTime": "",
  47. "keyword": "",
  48. "thirdType": 14,
  49. "siteCode": "44",
  50. "secondType": "A",
  51. "projectType": "",
  52. "dateType": "",
  53. "searchType": "pf",
  54. "total": 25311,
  55. "pageNo": page,
  56. "pageSize": 50,
  57. "openConvert": False
  58. }
  59. x_dgi = get_x_dgi(data)
  60. x_dgi['X-Dgi-Req-Timestamp'] = str(x_dgi['X-Dgi-Req-Timestamp'])
  61. self.headers.update(x_dgi)
  62. data = json.dumps(data, separators=(',', ':'))
  63. request.data = data
  64. request.headers = self.headers
  65. def parse(self, request, response):
  66. response.encoding = response.apparent_encoding
  67. menu = request.item
  68. info_list = response.json.get('data').get('pageData')
  69. for info in info_list:
  70. noticeSecondType = info.get('noticeSecondType')
  71. edition = info.get('edition')
  72. noticeId = info.get('noticeId')
  73. projectCode = info.get('projectCode')
  74. pubServicePlat = info.get('pubServicePlat')
  75. noticeSecondTypeDesc = info.get('noticeSecondTypeDesc')
  76. publishDate = info.get('publishDate')
  77. tradingProcess = info.get('tradingProcess')
  78. href = f"https://zbtb.gd.gov.cn/#/jygg/{edition}/{projectCode}/{noticeSecondType}/{tradingProcess}?rowGuid={noticeId}&siteName={pubServicePlat}&titleDetails={noticeSecondTypeDesc}"
  79. title = info.get('noticeTitle').strip()
  80. create_time = deal_time(publishDate)
  81. siteName = info.get('siteName', '').strip()
  82. area = "广东"
  83. city = siteName
  84. list_item = BidingListItem() # 存储数据的管道
  85. list_item.href = href # 标书链接
  86. list_item.unique_key = ('href',)
  87. list_item.channel = menu.get("channel") # 最上方定义的抓取栏目 (编辑器定的)
  88. list_item.spidercode = menu.get("code") # 最上方定义的爬虫code(编辑器定的)
  89. list_item.title = title # 标题
  90. list_item.site = self.site
  91. list_item.publishtime = create_time
  92. list_item.area = area # 城市默认:全国
  93. list_item.city = city # 城市 默认为空
  94. list_item.parse = "self.detail_get" # 详情页回调方法
  95. dparams = {
  96. "projectCode": projectCode,
  97. "tradingType": noticeSecondType,
  98. "tradingProcess": tradingProcess,
  99. "siteCode": "44"
  100. }
  101. list_item.request_params = {"params": dparams}
  102. list_item.deal_detail = []
  103. list_item.proxies = False
  104. list_item.parse_url = "https://zbtb.gd.gov.cn/ztbjg-portal/center/trading-notice/detail"
  105. yield list_item
  106. request = self.infinite_pages(request, response)
  107. yield request
  108. if __name__ == "__main__":
  109. ZtbpcFeapder(redis_key="lzz:gdsztbjgw_zbjh").start()