123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- # -*- coding: utf-8 -*-
- """
- Created on 2025-06-02
- ---------
- @summary: 芜湖市网上中介超市
- ---------
- @author: lzz
- """
- import feapder
- from items.spider_item import BidingListItem
- from collections import namedtuple
- from feapder.utils.tools import timestamp_to_date
- class ZtbpcFeapder(feapder.BiddingListSpider):
- def start_callback(self):
- self.site = "芜湖市网上中介超市"
- Menu = namedtuple('Menu', ['channel', 'code', 'tid', 'crawl_page'])
- self.menus = [
- Menu('采购公告', 'a_whswszjcs_cggg', '1', 1),
- ]
- self.headers = {
- "Accept": "application/json, text/plain, */*",
- "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
- "Cache-Control": "no-cache",
- "Connection": "keep-alive",
- "Content-Type": "application/x-www-form-urlencoded",
- "Origin": "https://wh.ahzwfw.gov.cn",
- "Pragma": "no-cache",
- "Referer": "https://wh.ahzwfw.gov.cn/wszjcs-web/views/projectnotice/projectnotice.html",
- "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",
- }
- def start_requests(self):
- for menu in self.menus:
- start_url = "https://wh.ahzwfw.gov.cn/wszjcs-web/tradingInformation/getTradingInformationPage.do"
- yield feapder.Request(url=start_url, item=menu._asdict(), page=1, proxies=False)
- def download_midware(self, request):
- page = request.page
- menu = request.item
- data = {
- "currentPageNo": f"{page}",
- "pageSize": "10",
- "filterType": menu.get('tid'),
- "projectName": "",
- "state": "",
- "isRelease": "",
- "uscCode": "",
- "winningAnnouncementStatus": "",
- "publicityStatus": "",
- }
- request.data = data
- request.headers = self.headers
- def parse(self, request, response):
- menu = request.item
- info_list = response.json.get('data').get('rows')
- for info in info_list:
- hid = info.get('id')
- t = int(menu.get('tid'))-1
- 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"
- title = info.get('projectName').strip()
- create_time = timestamp_to_date(int(str(info.get('creationTime'))[:10]))
- area = "安徽"
- city = "芜湖市"
- list_item = BidingListItem() # 存储数据的管道
- list_item.href = href # 标书链接
- list_item.unique_key = ('href',)
- list_item.channel = menu.get("channel") # 最上方定义的抓取栏目 (编辑器定的)
- list_item.spidercode = menu.get("code") # 最上方定义的爬虫code(编辑器定的)
- list_item.title = title # 标题
- list_item.site = self.site
- list_item.publishtime = create_time
- list_item.area = area # 城市默认:全国
- list_item.city = city # 城市 默认为空
- list_item.parse = "self.detail_get" # 详情页回调方法
- list_item.deal_detail = ['//div[@class="detail"]']
- list_item.proxies = False
- list_item.did = hid
- list_item.parse_url = href # 详情页请求地址
- yield list_item
- request = self.infinite_pages(request, response)
- yield request
- if __name__ == "__main__":
- ZtbpcFeapder(redis_key="lzz:wnjtdzzbcgpt_jggs").start()
|