当前位置: 首页 > 工具软件 > SuperAgent > 使用案例 >

TypeScript中使用superagent

鲍高扬
2023-12-01

一、superagent的npm地址:superagent - npm (npmjs.com)

二、代码示例

const superagent = require("superagent");

const fs = require("fs");

async function writeFile(html:string){

    fs.writeFileSync('index.html',html,"utf-8");

}

async function getHtml(){

    let htmlObj = await superagent.get("www.baidu.com");

    let html:string = htmlObj.text;

    await writeFile(html);

    console.log(html);

    return html;

}

getHtml();

 类似资料: