采购公告-列表页.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on 2025-06-02
  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 feapder.utils.tools import timestamp_to_date
  13. class ZtbpcFeapder(feapder.BiddingListSpider):
  14. def start_callback(self):
  15. self.site = "芜湖市网上中介超市"
  16. Menu = namedtuple('Menu', ['channel', 'code', 'tid', 'crawl_page'])
  17. self.menus = [
  18. Menu('采购公告', 'a_whswszjcs_cggg', '1', 1),
  19. ]
  20. self.headers = {
  21. "Accept": "application/json, text/plain, */*",
  22. "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
  23. "Cache-Control": "no-cache",
  24. "Connection": "keep-alive",
  25. "Content-Type": "application/x-www-form-urlencoded",
  26. "Origin": "https://wh.ahzwfw.gov.cn",
  27. "Pragma": "no-cache",
  28. "Referer": "https://wh.ahzwfw.gov.cn/wszjcs-web/views/projectnotice/projectnotice.html",
  29. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36",
  30. }
  31. def start_requests(self):
  32. for menu in self.menus:
  33. start_url = "https://wh.ahzwfw.gov.cn/wszjcs-web/tradingInformation/getTradingInformationPage.do"
  34. yield feapder.Request(url=start_url, item=menu._asdict(), page=1, proxies=False)
  35. def download_midware(self, request):
  36. page = request.page
  37. menu = request.item
  38. data = {
  39. "currentPageNo": f"{page}",
  40. "pageSize": "10",
  41. "filterType": menu.get('tid'),
  42. "projectName": "",
  43. "state": "",
  44. "isRelease": "",
  45. "uscCode": "",
  46. "winningAnnouncementStatus": "",
  47. "publicityStatus": "",
  48. }
  49. request.data = data
  50. request.headers = self.headers
  51. def parse(self, request, response):
  52. menu = request.item
  53. info_list = response.json.get('data').get('rows')
  54. for info in info_list:
  55. hid = info.get('id')
  56. t = int(menu.get('tid'))-1
  57. href = f"https://wh.ahzwfw.gov.cn/wszjcs-web/views/projectnotice/projectnotice.html#/projectDetail?id={hid}&type=-1&usc_code=&title={t}&selectAgain=false&mark=1"
  58. title = info.get('projectName').strip()
  59. create_time = timestamp_to_date(int(str(info.get('creationTime'))[:10]))
  60. area = "安徽"
  61. city = "芜湖市"
  62. list_item = BidingListItem() # 存储数据的管道
  63. list_item.href = href # 标书链接
  64. list_item.unique_key = ('href',)
  65. list_item.channel = menu.get("channel") # 最上方定义的抓取栏目 (编辑器定的)
  66. list_item.spidercode = menu.get("code") # 最上方定义的爬虫code(编辑器定的)
  67. list_item.title = title # 标题
  68. list_item.site = self.site
  69. list_item.publishtime = create_time
  70. list_item.area = area # 城市默认:全国
  71. list_item.city = city # 城市 默认为空
  72. list_item.parse = "self.detail_get" # 详情页回调方法
  73. list_item.deal_detail = ['//div[@class="detail"]']
  74. list_item.proxies = False
  75. list_item.did = hid
  76. list_item.parse_url = href # 详情页请求地址
  77. yield list_item
  78. request = self.infinite_pages(request, response)
  79. yield request
  80. if __name__ == "__main__":
  81. ZtbpcFeapder(redis_key="lzz:wnjtdzzbcgpt_jggs").start()