12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- # -*- 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
- import json
- class ZtbpcFeapder(feapder.BiddingListSpider):
- def start_callback(self):
- self.site = "江苏土地市场网"
- Menu = namedtuple('Menu', ['channel', 'code', 'crawl_page'])
- self.menus = [
- Menu('成交公告', 'a_jstdscw_cjgg', 1),
- ]
- self.headers = {
- "Accept": "*/*",
- "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
- "Cache-Control": "no-cache",
- "Connection": "keep-alive",
- "Content-Type": "application/json",
- "Origin": "http://www.landjs.com",
- "Pragma": "no-cache",
- "Referer": "http://www.landjs.com/tAfficheParcel/bargainParcel",
- "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",
- "X-Requested-With": "XMLHttpRequest"
- }
- def start_requests(self):
- for menu in self.menus:
- start_url = "http://www.landjs.com/tAfficheParcel/searchBargainParcel"
- yield feapder.Request(url=start_url, item=menu._asdict(), page=1, proxies=False)
- def download_midware(self, request):
- page = request.page
- data = {
- "index": page,
- "size": 10,
- "mrFlag": 2
- }
- data = json.dumps(data, separators=(',', ':'))
- request.data = data
- request.headers = self.headers
- def parse(self, request, response):
- menu = request.item
- info_list = response.json.get('bargainParcelList')
- for info in info_list:
- href = "http://www.landjs.com/tAfficheParcel/detail/bargain/" + info.get('cjgsGuid')
- title = info.get('xmMc')
- create_time = timestamp_to_date(int(str(info.get('createDate'))[: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="mainContent"]']
- list_item.parse_url = href # 详情页请求地址
- yield list_item
- request = self.infinite_pages(request, response)
- yield request
- if __name__ == "__main__":
- ZtbpcFeapder(redis_key="lzz:jstdscw_jydt").start()
|