永城信息网爬虫

永城信息网爬虫

一个小地方的信息网站竟然蕴含着大技术,该开发者把数据都藏在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}")

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

相关推荐
数据知道9 小时前
斩断 `navigator` 前端:底层重写 UserAgent/Platform/Language 属性描述符
爬虫·数据采集·指纹浏览器·浏览器指纹
深蓝电商API14 小时前
Playwright深入浅出:从入门到企业级项目实战
爬虫·playwright
小白学大数据15 小时前
爬虫性能天花板:asyncio赋能 Aiohttp,并发提速 10 倍
开发语言·爬虫·数据分析
yijianace20 小时前
Python爬虫实战:分页爬取 + 详情页采集 + CSV存储
前端·爬虫·python
yijianace21 小时前
Python爬虫实战:ThreadPoolExecutor多线程采集书籍信息与图片下载
开发语言·爬虫·python
在放️21 小时前
Python 爬虫 · bs4 模块基础
开发语言·爬虫·python
belong_my_offer1 天前
Python 数据采集完全指南 —— 从零开始掌握网络爬虫与文件读取
开发语言·爬虫·python
深蓝电商API1 天前
Playwright vs Puppeteer vs Selenium 2026终极对比
爬虫·selenium·puppeteer·playwright
遇事不決洛必達1 天前
【Python基础】GIL 锁是什么及其对爬虫的影响
爬虫·python·线程·进程·gil锁
綝~1 天前
爬虫数据采集工程师岗位面试题
爬虫·面试·请求