最新消息: USBMI致力于为网友们分享Windows、安卓、IOS等主流手机系统相关的资讯以及评测、同时提供相关教程、应用、软件下载等服务。

使用request库的get方法发起GET请求

维修 admin 30浏览 0评论

使用request库的get方法发起GET请求

// 导入所需的库
const request = require('request');
const cheerio = require('cheerio');// 设置代理信息,proxy_host: www.duoip, proxy_port: 8000
const proxy = {host: 'jshk',port: 1234
};// 定义要爬取的URL
const url = 'http://localhost:9200/_cat/indices';// 使用request库的get方法发起GET请求,并设置proxy参数
request.get(url, { proxy: proxy }, (error, response, body) => {if (!error && response.statusCode === 200) {// 使用cheerio库解析返回的HTMLconst $ = cheerio.load(body);// 查找所有的索引名称const indices = $('td').slice(1, -1).toArray().map(td => $(td).text());// 输出所有的索引名称console.log(indices);}
});

步骤:

  1. 引入所需的库:request和cheerio。

  2. 设置代理信息。

  3. 定义要爬取的URL。

  4. 使用request库的get方法发起GET请求,并设置proxy参数。

  5. 使用cheerio库解析返回的HTML。

  6. 查找所有的索引名称。

  7. 输出所有的索引名称。

使用request库的get方法发起GET请求

// 导入所需的库
const request = require('request');
const cheerio = require('cheerio');// 设置代理信息,proxy_host: www.duoip, proxy_port: 8000
const proxy = {host: 'jshk',port: 1234
};// 定义要爬取的URL
const url = 'http://localhost:9200/_cat/indices';// 使用request库的get方法发起GET请求,并设置proxy参数
request.get(url, { proxy: proxy }, (error, response, body) => {if (!error && response.statusCode === 200) {// 使用cheerio库解析返回的HTMLconst $ = cheerio.load(body);// 查找所有的索引名称const indices = $('td').slice(1, -1).toArray().map(td => $(td).text());// 输出所有的索引名称console.log(indices);}
});

步骤:

  1. 引入所需的库:request和cheerio。

  2. 设置代理信息。

  3. 定义要爬取的URL。

  4. 使用request库的get方法发起GET请求,并设置proxy参数。

  5. 使用cheerio库解析返回的HTML。

  6. 查找所有的索引名称。

  7. 输出所有的索引名称。

发布评论

评论列表 (0)

  1. 暂无评论