You need to enable JavaScript to run this app. 使用requests爬取保时捷招聘站职位仅得10条,无法获取全部50条求解决方案
优惠活动
大模型
产品
解决方案
定价
更多

使用requests爬取保时捷招聘站职位仅得10条,无法获取全部50条求解决方案

解决方案

核心原因

该接口后端限制了单次请求最多返回10条数据,即使参数中CountItem设置为50也不会生效,需要通过分页请求获取全部50条数据。另外你直接复制的编码后URL存在转义错误,会导致参数识别异常。

修正后代码

import requests
import json
import urllib.parse

s = requests.Session()

headers = {
    'Connection': 'keep-alive',
    'Pragma': 'no-cache',
    'Cache-Control': 'no-cache',
    'sec-ch-ua': '"Google Chrome";v="119", "Chromium";v="119", "Not?A_Brand";v="24"',
    'Accept': 'application/json, text/javascript, */*; q=0.01',
    'sec-ch-ua-mobile': '?0',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36',
    'Origin': 'https://jobs.porsche.com',
    'Sec-Fetch-Site': 'same-site',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Dest': 'empty',
    'Referer': 'https://jobs.porsche.com/',
    'Accept-Language': 'en-US,en;q=0.9',
}

# 基础查询参数模板
base_query = {
    "LanguageCode": "DE",
    "SearchParameters": {
        "FirstItem": 1,
        "CountItem": 10,
        "Sort": [
            {"Criterion": "PublicationStartDate", "Direction": "DESC"}
        ],
        "MatchedObjectDescriptor": [
            "ID","PositionTitle","PositionURI","PositionLocation.CountryName",
            "PositionLocation.CityName","PositionLocation.Longitude","PositionLocation.Latitude",
            "PositionLocation.PostalCode","PositionLocation.StreetName","PositionLocation.BuildingNumber",
            "PositionLocation.Distance","JobCategory.Name","PublicationStartDate",
            "ParentOrganizationName","ParentOrganization","OrganizationShortName",
            "CareerLevel.Name","JobSector.Name","PositionIndustry.Name",
            "PublicationCode","PublicationChannel.Id"
        ]
    },
    "SearchCriteria": [
        {"CriterionName": "PublicationChannel.Code", "CriterionValue": ["12"]},
        {"CriterionName": "PublicationChannel.Code", "CriterionValue": ["12"]}
    ]
}

all_jobs = []
# 分5页请求,每次10条
for page in range(5):
    # 计算当前页起始序号
    base_query["SearchParameters"]["FirstItem"] = page * 10 + 1
    # 把查询参数转成URL编码字符串
    encoded_data = urllib.parse.quote(json.dumps(base_query, separators=(',', ':')))
    url = f"https://api-jobs.porsche.com/search/?data={encoded_data}"
    resp = s.get(url, headers=headers).json()
    # 提取当前页职位列表,根据接口返回的字段调整key,一般职位列表在SearchResult/MatchedObject下
    current_jobs = resp.get("SearchResult", {}).get("MatchedObject", [])
    all_jobs.extend(current_jobs)
    print(f"第{page+1}页获取到{len(current_jobs)}条职位")

print(f"总共获取到{len(all_jobs)}条职位")
# 打印所有职位名称
for job in all_jobs:
    print(job.get("PositionTitle"))

说明

  • 自动分页请求,每次取10条,5次即可取满50条数据
  • 不再直接使用复制的转义URL,而是通过代码动态构造参数并编码,避免转义错误
  • 修正了sec-ch-ua参数为空的问题,降低被反爬拦截的概率

内容的提问来源于stack exchange,提问作者Dan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.14 18:27:03