永城信息网爬虫

永城信息网爬虫

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

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

相关推荐
wuyk5551 天前
Spider-第16讲-线程池与竞态问题
大数据·爬虫·python·elasticsearch·搜索引擎
wuyk5553 天前
Spider-第14讲-表单提交与CSRF
前端·爬虫·python·elasticsearch·csrf
wuyk5555 天前
Spider-第11讲-工程化改造与可维护性
大数据·爬虫·elasticsearch·搜索引擎
wuyk5555 天前
Spider-第12讲-asyncio异步并发爬取
大数据·爬虫·elasticsearch·搜索引擎
小宋10215 天前
AI 爬虫把大学图书馆站点拖垮:按行为指纹给爬虫分类、按类发配额、用边缘缓存分层,以带宽成本结构和真实用户 P95 延迟定档
人工智能·爬虫·分类
wuyk5556 天前
Spider-第10讲-SQLite持久化与去重
数据库·爬虫·sqlite
wuyk5556 天前
Spider-第09讲-三格式落盘CSV-Excel-JSON
爬虫·python·json·excel
wuyk5557 天前
Spider-第07讲-JSON接口与正则提取
爬虫·python·json
feasibility.7 天前
一物降一物?AI逆向没有终局:REA拆App,BLA设套,LASIK清场
人工智能·爬虫·github·逆向·skill·rea
wuyk5559 天前
Spider-第03讲-HTTP速通与读懂响应
网络·爬虫·网络协议·http