使用Axios的HTTP请求

编程入门 行业动态 更新时间:2024-10-15 20:25:01

使用<a href=https://www.elefans.com/category/jswz/34/1771419.html style=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请求

本文发布于:2024-05-07 10:21:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1755800.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Axios   HTTP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!