原创文章,转载请注明出处
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"
}

rog_api = "https://rog.asus.com/support/webapi/product/GetPDBIOS"
bot_api = "https://api.telegram.org/bot{api}/sendMessage".format(api=tg_bot_api)


def send_notify(version, description, release_date, link):

    params = {
        "chat_id": tg_chat_id,
        "text": "BIOS version update to " + version + " now.\n\n"
                + description + "\n"
                + "\n" + release_date + link
    }
    send_message = requests.post(url=bot_api, params=params, headers=headers)
    print(send_message.json())


def get_bios():

    params = {
        "website": "us",
        "model": "ROG-CROSSHAIR-VI-HERO",
        "pdid": 9262,
        "cpu": "",
        "LevelTagId": 5341
    }
    get_information = requests.get(url=rog_api, params=params, headers=headers)
    latest_bios = get_information.json()["Result"]["Obj"][0]["Files"][0]
    bios_version = latest_bios["Version"]
    bios_description = latest_bios["Description"]
    bios_release_date = latest_bios["ReleaseDate"]
    dl_link = latest_bios["DownloadUrl"]["Global"]

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


def main():
    get_bios()


if __name__ == "__main__":
    main()

0 条评论

发表回复

Avatar placeholder

您的电子邮箱地址不会被公开。 必填项已用*标注

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