永城信息网爬虫

永城信息网爬虫

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

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

相关推荐
TlSfoward16 小时前
抓包代理链路下的 TLS 指纹变化分析 TLSFOWARD抓包工具
数据库·爬虫·网络协议·搜索引擎·php
电商API_1800790524718 小时前
企业ERP进销存场景|京东商品详情接口自动同步方案|凭证鉴权批量调用技术实操
大数据·运维·人工智能·爬虫·数据挖掘·网络爬虫
拓海SEO外贸20 小时前
Google 爬虫管理:抓取预算、404 与重定向
爬虫·搜索引擎·信息可视化·seo·跨境电商·独立站搭建·seo优化
深蓝电商API21 小时前
浏览器缓存机制对爬虫有什么影响?
爬虫
Dontla1 天前
网站爬虫控制策略介绍(robots.txt、sitemap.xml、x-robots-tag、noindex、nofollow)网站索引
xml·爬虫·dubbo
Bright Data1 天前
DuckDuckGo 搜索爬取器
爬虫·serp·网页数据
去码头整点薯条ing2 天前
某当网登录滑块【协议+OCR】
爬虫·python·ocr
上海云盾-小余2 天前
中小站点防护避坑:低价高防服务存在的各类安全短板剖析
网络·爬虫·安全·ddos
huangdong_2 天前
电商图片下载工具技术选型与稳定性深度解析:从爬虫到浏览器方案的完整技术演进与源码级实现
爬虫
阿标在干嘛2 天前
从单机到分布式:政策快报爬虫系统的三次重构
分布式·爬虫·重构