123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- # -*- coding: utf-8 -*-
- """
- Created on 2025-04-24
- ---------
- @summary: TCM供应链平台
- ---------
- @author: lzz
- """
- import feapder
- from items.spider_item import MgpListItem
- from collections import namedtuple
- class Feapder(feapder.BiddingListSpider):
- def start_callback(self):
- Menu = namedtuple('Menu', ['channel', 'code', 'crawl_page'])
- self.site = "TCM供应链平台"
- self.menus = [
- Menu('招标公告', 'a_tclgylpt_zbgg', 1),
- ]
- self.VIEWSTATE = ""
- self.cookies = {}
- self.EVENTVALIDATION = ""
- self.VIEWSTATEENCRYPTED = ""
- def start_requests(self):
- for menu in self.menus:
- start_url = "https://tcm.cxtc.com/site/BiddingList.aspx"
- yield feapder.Request(url=start_url, item=menu._asdict(), page=1, proxies=False)
- def download_midware(self, request):
- request.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": "no-cache",
- "Connection": "keep-alive",
- "Content-Type": "application/x-www-form-urlencoded",
- "Origin": "https://tcm.cxtc.com",
- "Pragma": "no-cache",
- "Referer": "https://tcm.cxtc.com/site/BiddingList.aspx",
- "Upgrade-Insecure-Requests": "1",
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36",
- }
- page = request.page
- if page != 1:
- data = {
- "__EVENTTARGET": "ctl00$MainContent$gv1",
- "__EVENTARGUMENT": f"Page${page}",
- "__VIEWSTATE": self.VIEWSTATE,
- "__VIEWSTATEENCRYPTED": self.VIEWSTATEENCRYPTED,
- "__EVENTVALIDATION": self.EVENTVALIDATION,
- "ctl00%24MainContent%24SearchTxt": "",
- "ctl00%24MainContent%24SearchTxt2": ""
- }
- request.data = data
- request.cookies = self.cookies
- def parse(self, request, response):
- self.cookies = response.cookies.get_dict()
- self.VIEWSTATE = response.xpath('//input[@id="__VIEWSTATE"]/@value').extract_first("")
- self.EVENTVALIDATION = response.xpath('//input[@id="__EVENTVALIDATION"]/@value').extract_first("")
- self.VIEWSTATEENCRYPTED = response.xpath('//input[@id="__VIEWSTATEENCRYPTED"]/@value').extract_first("")
- menu = request.item
- info_list = response.xpath('//table[@id="MainContent_gv1"]/tr')
- for info in info_list[1:-1]:
- href = info.xpath('./td[1]/div/a/@href').extract_first()
- title1 = info.xpath('./td[1]/div/a/text()').extract_first("")
- title = title1 + info.xpath('./td[2]/text()').extract_first().strip()
- create_time = info.xpath('./td[3]/text()').extract_first().strip().replace('/','-')
- area = "全国" # 省份
- city = "" # 城市
- list_item = MgpListItem() # 存储数据的管道
- list_item.href = href # 标书链接
- list_item.unique_key = ('title', 'href', create_time)
- 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 = [] # 抽取正文xpath
- list_item.proxies = False
- list_item.parse_url = href # 详情页请求地址
- yield list_item
- # 无限翻页
- request = self.infinite_pages(request, response)
- yield request
- if __name__ == "__main__":
- Feapder(redis_key="lzz:tclgylpt_zbgg").start()
|