原创文章,转载请注明出处
https://qiedd.com/

抓取API

首先我们需要抓取 API ,通过浏览器 F12 慢慢找,这里以华硕的 BIOS 为例
F12 – Network

反代API

我们用 Cloudflare works 来反代目标 URL,从而实现使用 Cloudflare 的 IP 池来抓取

addEventListener(
  "fetch",event => {
     let url=new URL(event.request.url);
     url.hostname="rog.asus.com";
     let request=new Request(url,event.request);
     event. respondWith(
       fetch(request)
     )
  }
)

Python

使用了 Requests 库

import requests

tg_bot_api = ""
tg_chat_id = 

headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36"
}


def send_notify(bot_api, chat_id, version, description, release_date, link):
    url = "https://api.telegram.org/bot{api}/sendMessage".format(api=bot_api)
    params = {
        "chat_id": chat_id,
        "text": "BIOS version update to " + version + " now.\n\n"
                + description + "\n"
                + "\n" + release_date + link
    }
    send_message = requests.post(url=url, params=params, headers=headers)
    print(send_message.json())


def get_bios():
    # 这里可以使用反代的URL
    url = "https://rog.asus.com/support/webapi/product/GetPDBIOS"
    params = {
        "website": "us",
        "model": "ROG-CROSSHAIR-VI-HERO",
        "pdid": 9262,
        "cpu": "",
        "LevelTagId": 5341
    }
    get_information = requests.get(url=url, params=params, headers=headers)
    
    # 处理JSON
    bios_version = get_information.json()["Result"]["Obj"][0]["Files"][0]["Version"]
    bios_description = get_information.json()["Result"]["Obj"][0]["Files"][0]["Description"]
    bios_release_date = get_information.json()["Result"]["Obj"][0]["Files"][0]["ReleaseDate"]
    dl_link = get_information.json()["Result"]["Obj"][0]["Files"][0]["DownloadUrl"]["Global"]

    # 替换<br>为\n
    bios_description = bios_description.replace("<br/>", "\n")
    if bios_version != "8101":
        send_notify(tg_bot_api, tg_chat_id, bios_version, bios_description, bios_release_date, dl_link)


get_bios()

0 条评论

发表评论

Avatar placeholder

您的电子邮箱地址不会被公开。

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据