Axios的HTTP请求"/>
使用Axios的HTTP请求
我正在尝试使用NodeJS爬行网站。我正在使用Axios发出HTTP请求。我只能提取加载网页时可用的那些项目。我向下滚动时加载的所有HTML都不会被获取。
这是我的代码。
const axios = require('axios');
const cheerio = require('cheerio');
var request = require('request');
// table view
const url = ";_sortDirection=asc&study=Engineering&_mode=table";
fetchData(url).then((res) => {
const html = res.data;
const $ = cheerio.load(html);
const unilist = $('.TableTabular__TableContainer-febmbj-0.guaRKP > tbody > tr >td ');
unilist.each(function() {
let title = $(this).find('div').attr("name");
if (typeof(title) == 'string') {
console.log(title);
}
});
})
async function fetchData(url){
console.log("Crawling data...")
// make http call to url
let response = await axios(url).catch((err) => console.log(err));
if(response.status !== 200){
console.log("Error occurred while fetching data");
return;
}
return response;
}
我正在尝试获取所有大学名称。但是,我只能获得13所大学,因为只有在手动向下滚动页面时才会加载其他大学。
我如何访问网页中的所有大学:;_sortDirection=asc&study=Engineering&_mode=table
回答如下:更多推荐
使用Axios的HTTP请求
发布评论