永城信息网爬虫

永城信息网爬虫

一个小地方的信息网站竟然蕴含着大技术,该开发者把数据都藏在js中,对于爬虫新手来说还是非常有难度的,废话不都说,上代码

bash 复制代码
import requests
import json
import re
import os
import time

LIST_API = "https://www.ycxinxi.com/new/api/v1/infoList"
DETAIL_API = "https://www.ycxinxi.com/new/api/v1/infoDetail"

headers = {
    "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36"
}

proxies = {
    'http': os.environ.get('HTTP_PROXY') or os.environ.get('http_proxy'),
    'https': os.environ.get('HTTPS_PROXY') or os.environ.get('https_proxy')
}
proxies = {k: v for k, v in proxies.items() if v}

try:
    # 获取列表
    params = {"cat": 3, "page": 2, "callback": "jsonp_callback"}
    res = requests.get(LIST_API, params=params, headers=headers, timeout=10, proxies=proxies or None, verify=False)
    json_str = re.search(r'jsonp_callback\((.*)\)', res.text).group(1)
    data = json.loads(json_str)

    if data.get('code') == '00':
        jobs = data.get('data', {}).get('list', [])
        print(f"共找到 {len(jobs)} 条招聘信息\n")

        for i, job in enumerate(jobs, 1):
            job_id = job.get('id')
            print(f"\n{'='*80}")
            print(f"第 {i} 条 标题:{job.get('title')}招聘详情 (ID: {job_id})")
            print('='*80)

            # 获取详情
            detail_params = {"id": job_id, "callback": "jsonp_callback"}
            detail_res = requests.get(DETAIL_API, params=detail_params, headers=headers, timeout=10, proxies=proxies or None, verify=False)
            detail_json = re.search(r'jsonp_callback\((.*)\)', detail_res.text).group(1)
            detail_data = json.loads(detail_json)

            if detail_data.get('code') == '00':
                detail = detail_data.get('data', {})
                for key, value in detail.items():
                    print(f"{key}: {value}")

            time.sleep(0.5)  # 避免请求过快

except Exception as e:
    print(f"❌ 错误: {e}")

该代码仅供学习使用,爬虫有风险,操作需谨慎

相关推荐
quantdash_cc10 小时前
告别自建 Requests/BS4 网页爬虫:基于 QuantDash 搭建零维保的高性能量化行情流水线
开发语言·爬虫·python·pandas·量化·quantdash
Patrick在香港18 小时前
Python爬虫框架实战:优雅抓取香港政府公开API数据的通用方案
java·开发语言·爬虫·python·ai编程·数据可视化·可用性测试
鬼手点金2 天前
与LLM结合的主流智能爬虫框架
爬虫·python·llm·post·request·firecrawl·crawl4ai
天启HTTP3 天前
爬虫频繁弹验证码?解析网站反爬检测机制
网络·爬虫·tcp/ip
深蓝电商API3 天前
如何快速定位加密函数?
爬虫·加密函数
oh,huoyuyan3 天前
网页公开数据采集工具推荐
人工智能·爬虫·火车采集器
崔子末3 天前
某影视库剧集列表以及查询接口逆向
爬虫·python
雪山青木4 天前
全国微博签到数据201912-202004
大数据·爬虫·python·数据挖掘·数据分析·新浪微博
TlSfoward4 天前
DLL 指纹库 采集、检索 TLSFOWARD tls指纹库
爬虫·网络协议·https·自动化
有味道的男人5 天前
基于 Codex 爬虫构建亚马逊无人上架系统|竞品详情采集到商品发布完整实现
爬虫·亚马逊