政府采购-列表页.py 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on2025-05-20
  4. ---------
  5. @summary: 湖南省公共资源交易服务平台新网址
  6. ---------
  7. @author: lzz
  8. """
  9. import feapder
  10. from items.spider_item import MgpListItem
  11. from collections import namedtuple
  12. class ZtbpcFeapder(feapder.BiddingListSpider):
  13. def start_callback(self):
  14. self.site = "湖南省公共资源交易服务平台新网址"
  15. Menu = namedtuple('Menu', ['channel', 'code', 'crawl_page'])
  16. self.menus = [
  17. Menu('政府采购', 'hn_hnsggzyjyfwptxwz_zfcg', 20),
  18. ]
  19. self.headers = {
  20. "Accept": "application/json, text/plain, */*",
  21. "Accept-Language": "zh-CN,zh;q=0.9",
  22. "Cache-Control": "no-cache",
  23. "Connection": "keep-alive",
  24. "Pragma": "no-cache",
  25. "Referer": "https://hnsbenji.hnsggzy.com/",
  26. "Sec-Fetch-Site": "same-origin",
  27. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36",
  28. }
  29. def start_requests(self):
  30. for menu in self.menus:
  31. start_url = "https://hnsbenji.hnsggzy.com/tradeApi/governmentPurchase/projectInformation/selectAll"
  32. yield feapder.Request(url=start_url, item=menu._asdict(), page=1, proxies=False)
  33. def download_midware(self, request):
  34. page = request.page
  35. params = {
  36. "current": f"{page}",
  37. "size": "10",
  38. }
  39. request.params = params
  40. request.headers = self.headers
  41. def parse(self, request, response):
  42. menu = request.item
  43. info_list = response.json.get('data').get('records')
  44. for info in info_list:
  45. hid = info.get('fileId')
  46. regionCode = info.get('regionCode')
  47. href = f"https://hnsbenji.hnsggzy.com/#/resources/projectDetail/governmentPurchase?id={hid}&regionCode={regionCode}"
  48. title = info.get('noticeName').strip()
  49. publish_time = info.get('noticeSendTime').split('T')[0]
  50. area = "湖南" # 省份
  51. city = "" # 城市
  52. district = "" # 区县
  53. list_item = MgpListItem() # 存储数据的管道
  54. list_item.href = href # 标书链接
  55. list_item.channel = menu.get("channel") # 最上方定义的抓取栏目 (编辑器定的)
  56. list_item.spidercode = menu.get("code") # 最上方定义的爬虫code(编辑器定的)
  57. list_item.title = title # 标题
  58. list_item.publishtime = publish_time # 标书发布时间
  59. list_item.site = self.site
  60. list_item.area = area or "全国" # 省份 默认:全国
  61. list_item.city = city # 城市 默认 为空
  62. list_item.district = district # 区县 默认 为空
  63. list_item.unique_key = ('href',)
  64. list_item.parse = "self.detail_get" # 详情页回调方法
  65. list_item.deal_detail = []
  66. list_item.proxies = False
  67. list_item.parse_url = f"https://hnsbenji.hnsggzy.com/tradeApi/governmentPurchase/projectInformation/selectProjectInformation/{hid}" # 详情页请求地址
  68. yield list_item
  69. # 翻页 criter
  70. request = self.infinite_pages(request, response)
  71. yield request
  72. if __name__ == "__main__":
  73. ZtbpcFeapder(redis_key="lzz:hnsggzyjyfwptxwz_zfcg").start()