You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过POST请求爬取数据?求指导爬取指定网站医生信息

爬取Steer Health医生信息的解决方案

问题分析

你之前的POST请求未返回结果,核心原因包括:

  • 请求参数格式错误(网站要求JSON格式而非表单格式)
  • 缺少必要请求头(服务器会验证请求来源)
  • 遗漏了必填的searchId参数(取自目标页面URL的路径字段)

修正步骤及代码

1. 确认真实请求细节

打开目标页面,按下F12启动浏览器开发者工具,切换到Network标签:

  • 搜索doctor-search接口,查看请求的Headers(确认需携带的字段)和Request Payload(确认完整参数结构)

2. 调整后的爬取代码

import requests

# 模拟浏览器请求头,避免被服务器拦截
headers = {
    'Referer': 'https://intake.steerhealth.io/doctor-search/ae44936d8c986da0787e50a4b4e9ede602',
    'Content-Type': 'application/json',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36'
}

# 完整请求参数,包含必填的searchId
payload = {
    'name': "",
    'specialty': "",
    'distance': "",
    'location': "",
    'searchId': 'ae44936d8c986da0787e50a4b4e9ede602'
}

# 发送JSON格式的POST请求
response = requests.post(
    'https://intake.steerhealth.io/api/doctor-search',
    headers=headers,
    json=payload
)

# 解析并提取数据
if response.status_code == 200:
    doctor_data = response.json()
    # 遍历提取姓名和地址(字段名根据实际返回的JSON结构调整)
    for doctor in doctor_data.get('doctors', []):
        full_name = f"{doctor.get('firstName')} {doctor.get('lastName')}"
        address = doctor.get('address', {}).get('fullAddress')
        print(f"医生姓名: {full_name}")
        print(f"地址: {address}\n")
else:
    print(f"请求失败,状态码: {response.status_code}, 响应内容: {response.text}")

3. 额外注意事项

  • 若返回结果为空,检查开发者工具的Request Payload是否存在其他必填参数(如分页参数page)
  • 若网站有反爬机制,需从浏览器请求头中复制Cookie字段添加到代码的headers中
  • 控制请求频率,避免IP被服务器封禁

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.13 01:30:49