北京出入境可预约时间段查询

北京出入境可预约时间段查询

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import requests
import time

# 预定义的区域列表
regions = [
{"code": "110000", "node": "出入境管理总队"},
{"code": "110105", "node": "朝阳区"},
{"code": "110101", "node": "东城区"},
{"code": "110102", "node": "西城区"},
{"code": "110106", "node": "丰台区"},
{"code": "110107", "node": "石景山区"},
{"code": "110108", "node": "海淀区"},
{"code": "110109", "node": "门头沟区"},
{"code": "110111", "node": "房山区"},
{"code": "110112", "node": "通州区"},
{"code": "110113", "node": "顺义区"},
{"code": "110114", "node": "昌平区"},
{"code": "110115", "node": "大兴区"},
{"code": "110116", "node": "怀柔区"},
{"code": "110117", "node": "平谷区"},
{"code": "110228", "node": "密云区"},
{"code": "110229", "node": "延庆区"}
]

# 预定义的日期列表
dates = [
{"code": "2025-03-15", "node": "2025-03-15(星期六)"},
]

headers = {
"Accept": "*/*",
"Accept-Language": "zh-CN,zh;q=0.9",
"Connection": "keep-alive",
"Referer": "https://zwfw.gaj.beijing.gov.cn/crjfjj/apply/toBookRedo",
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-origin",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36",
"X-Requested-With": "XMLHttpRequest",
"sec-ch-ua": '"Not A(Brand";v="8", "Chromium";v="132", "Google Chrome";v="132"',
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "macOS"
}


def fetch_local_offices(region_code):
url = f"https://zwfw.gaj.beijing.gov.cn/crjfjj/api/getSldtByXzqh?sldttype=3,5,6&xzqh={region_code}&t={int(time.time() * 1000)}"
response = requests.get(url, headers=headers)
if response.status_code == 200:
try:
return response.json()
except Exception as e:
print(f"解析 JSON 失败: {e}")
return []
else:
print(f"获取区域 {region_code} 受理点失败,状态码: {response.status_code}")
return []


def fetch_appointments(local_code, date_code, local_name, date_name):
url = f"https://zwfw.gaj.beijing.gov.cn/crjfjj/api/getSjdSl?sld={local_code}&rq={date_code}&t={int(time.time() * 1000)}"
response = requests.get(url, headers=headers)
if response.status_code == 200:
try:
data = response.json()
print(f"请求地点: {local_name} 日期: {date_name}")
for item in data:
if int(item.get("sys", 0)) > 0:
print("找到可预约时间:", item)
except Exception as e:
print(f"解析 JSON 失败: {e}")
else:
print(f"获取预约信息失败, 状态码: {response.status_code}")


# 遍历所有区域
for region in regions:
print(f"正在获取区域: {region['node']}")
local_offices = fetch_local_offices(region['code'])
if not local_offices:
print(f"区域 {region['node']} 无可用受理点")
continue

# 遍历所有受理点
for local in local_offices:
for date in dates:
fetch_appointments(local['code'], date['code'], local['node'], date['node'])
time.sleep(1) # 防止请求过快