简体   繁体   English

尝试使用 jquery 获取“标题”时使用 axios 出现错误 403

[英]Getting error 403 with axios while trying to fetch 'title' with jquery

I am trying to scrape title off website with axios and cheerio我正在尝试使用 axios 和cheerio 从网站上刮掉标题

This is my function:这是我的 function:

async function getWebsiteInfo(uniqueId, req, res) {
    const axios = require('axios');
    const cheerio = require('cheerio');

    axios.get(req.body.url)
        .then(response => {
            const html = response.data;
            const $ = cheerio.load(html);
            const scrapedata = $('title').first().text();
            console.log(scrapedata);
            var object = {
                "uuid": uniqueId,
                "url": req.body.url,
                "info": scrapedata
            }

            addToDatabase(object, res);
        }).catch(error => {
            console.log(error);
        });
}

Anything I can do to not get an error 403?我能做些什么来避免出现错误 403?

Look at the headers your browser sends in the network panel and try sending that:查看浏览器在网络面板中发送的标题并尝试发送:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM