ปรึกษาเรื่อง Python get api url ตรง api url จำกัด limit ได้แค่ 1000 limit จะใช้ loop parameter next ได้อย่างไร

ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา ปรึกษาเรื่อง Python get api url ตรง api url จำกัด limit ได้แค่ 1000 limit จะใช้ loop parameter next ได้อย่างไร

ปรึกษาเรื่อง Python get api url ตรง api url จำกัด limit ได้แค่ 1000 limit จะใช้ loop parameter next ได้อย่างไร
***กรณี next ไม่ใช่ตัวเลขหน้า ที่คล้ายๆ page ครับ***

1. ยิง URL ได้ข้อมูลกลับมาทีละ 1000 อัน คือ ข้อมูลที่ 1-1000 ( api url จำกัด limit ได้แค่ 1000)

2. ถ้าใส่ Parameter next ไปใน URL ด้วย ก็ได้มา 1000 อัน แต่จะเริ่มต้นที่อันที่ 1001 (ข้อมูลที่ 1001-2000 จะloop ได้ 1000 เหมือนกัน)

3. ขอวิธีตัวอย่าง loop parameter next ครับ (ไม่ใช่ next_page =1,2,3)

4.code python
import requests
import json

url = "https://api.xxx.com/"
api_key ="test"
user = "abc@test.co.th"

headers = {
"Content-Type": "application/json",
"Authorization": "apikey " + user + ":" + api_key
}

response = requests.get(url, verify=False, headers=headers)
data = response.json()
print(json.dumps(data, indent=4))

if (response.status_code == 200):
 print("status_code = " + str(response.status_code) + " The request was a success!")

elif (response.status_code == 404):
print("status_code = " + str(response.status_code) + " Result not found!")

5. จะเป็นส่วน response ซึ่งมีข้อมูล response มาเยอะ ผมจะเอาส่วนที่ meta มาให้ช่วยดูครับ ว่าตรง next จะใช้ loop parameter next อย่างไรครับ
"meta": {
    "total_count": 2234,
    "offset": 0,
    "limit": 1000,
    "took": 138,
    "next": "/api/v2/intelligence/?q=%28%28status%3D%27active%27%29+and+%28confidence%3E%3D90%29+and+%28country%3D%27TH%27%29%29&search_after=1628780720222%2C57395475643&limit=1000"
   }


Tor Channels 103.120.115.xxx 07-09-2021 12:04:44

คำแนะนำ และการใช้งาน

สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก


  • ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
  • เปลี่ยน


    ( หรือ เข้าใช้งานผ่าน Social Login )

 ความคิดเห็นที่ 1
ไม่ค่อยแน่ใจ ลองเทียบค่าจาก meta สักสองค่า เท่าที่ดูค่า property offset หรือเปล่าที่จะเป็นตัวกำหนดค่า next ที่คืนค่ากลับมา


ninenik 223.24.151.xxx 07-09-2021
 ความคิดเห็นที่ 2
ผลลอง set limit=2 ข้อมูล response  meta มา 2 limit ครับ ส่วน next น่าจะใช้ในการ next ค่าต่อไปครับ
{
    "objects": [
        {
            "source_created": null,
            "status": "active",
            "itype": "bot_ip",
            "expiration_ts": "2021-12-07T02:27:41.016Z",
            "ip": "49.228.103.110",
            "is_editable": false,
            "feed_id": 18,
            "update_id": 12122521667,
            "value": "49.228.103.110",
            "is_public": false,
            "threat_type": "bot",
            "workgroups": [],
            "rdns": null,
            "confidence": 99,
            "uuid": "db61717d-6f71-4f04-b3eb-e36a91b863b2",
            "retina_confidence": 99,
            "trusted_circle_ids": [
                146,
                193
            ],
            "id": 57521646091,
            "source": "CI Army",
            "owner_organization_id": 2,
            "import_session_id": null,
            "source_modified": null,
            "type": "ip",
            "sort": [
                1631068075782,
                "57521646091"
            ],
            "description": null,
            "tags": null,
            "threatscore": 25,
            "latitude": 13.7159,
            "modified_ts": "2021-09-08T02:27:55.782Z",
            "org": "AIS Fibre",
            "asn": "133481",
            "created_ts": "2021-09-08T02:27:55.782Z",
            "tlp": null,
            "is_anonymous": false,
            "country": "TH",
            "source_reported_confidence": 75,
            "can_add_public_tags": false,
            "longitude": 100.417,
            "subtype": null,
            "meta": {
                "detail2": "imported by user 668",
                "severity": "low"
            },
            "resource_uri": "/api/v2/intelligence/57521646091/"
        },
        {
            "source_created": null,
            "status": "active",
            "itype": "brute_ip",
            "expiration_ts": "2021-12-07T02:27:39.874Z",
            "ip": "161.82.147.12",
            "is_editable": false,
            "feed_id": 1103,
            "update_id": 12122520295,
            "value": "161.82.147.12",
            "is_public": true,
            "threat_type": "brute",
            "workgroups": [],
            "rdns": null,
            "confidence": 100,
            "uuid": "4a17ce8f-ef11-443f-908e-19aa8cc47e5f",
            "retina_confidence": 100,
            "trusted_circle_ids": null,
            "id": 57521644943,
            "source": "BruteForcer IP Blocklist",
            "owner_organization_id": 2,
            "import_session_id": null,
            "source_modified": null,
            "type": "ip",
            "sort": [
                1631068067743,
                "57521644943"
            ],
            "description": null,
            "tags": null,
            "threatscore": 25,
            "latitude": 13.7618,
            "modified_ts": "2021-09-08T02:27:47.743Z",
            "org": "Symphony Communication",
            "asn": "",
            "created_ts": "2021-09-08T02:27:47.743Z",
            "tlp": null,
            "is_anonymous": false,
            "country": "TH",
            "source_reported_confidence": 0,
            "can_add_public_tags": false,
            "longitude": 100.5324,
            "subtype": null,
            "meta": {
                "detail2": "imported by user 668",
                "severity": "low"
            },
            "resource_uri": "/api/v2/intelligence/57521644943/"
        }
    ],
    "meta": {
        "total_count": 2266,
        "offset": 0,
        "limit": 2,
        "took": 192,
        "next": "/api/v2/intelligence/?q=%28%28status%3D%27active%27%29+and+%28confidence%3E%3D90%29+and+%28country%3D%27TH%27%29%29&search_after=1631068067743%2C57521644943&limit=2"
    }
}
status_code = 200 The request was a success!




Tor Channels 103.120.115.xxx 08-09-2021 13:26






เว็บไซต์ของเราให้บริการเนื้อหาบทความสำหรับนักพัฒนา โดยพึ่งพารายได้เล็กน้อยจากการแสดงโฆษณา โปรดสนับสนุนเว็บไซต์ของเราด้วยการปิดการใช้งานตัวปิดกั้นโฆษณา (Disable Ads Blocker) ขอบคุณครับ