01.
import requests
02.
import json
03.
04.
# url =
"www.api.xxx.com"
05.
api_key =
"test"
06.
user =
"abc@test.co.th"
07.
08.
09.
10.
headers = {
11.
"Content-Type"
:
"application/json"
,
12.
"Authorization"
:
"apikey "
+ user +
":"
+ api_key,
13.
}
14.
15.
# 2. ใช้เทคนิคแยกข้อความ ใช้เป็น URL
16.
# link API ตั้งต้น
18.
19.
# link Query ข้อมูล เอาจาก next json
20.
next_path =
"/api/v2/intelligence/?q=%28%28status%3D%27active%27%29+and+%28confidence%3E%3D90%29+and+%28country%3D%27TH%27%29%29&search_after=1630461816628%2C57480266984&limit=1000"
21.
22.
for
i in range(1, 3):
23.
# ปิด url
25.
26.
# ใน loop ทุกรอบ ให้สร้าง url ที่ใช้ดึงข้อมูลทีละชุด
27.
full_url = base_url + next_path
28.
29.
response = requests.get(full_url, headers=headers, verify=False)
30.
response_json = response.json()
31.
32.
# 1. ดึงค่า next ออกมาจาก response_json
33.
response_json[
'meta'
][
'next'
]
34.
35.
print(json.dumps(response_json, indent=2))