Node.js Instagram Scraper在本地运行,但不在Heroku上运行
我用这个脚本在Instagram上抓取一个用户页面。当我在本地运行它时,运行良好,我得到了包含我需要的信息的JSON。但当我部署到Heroku时,我无法正常运行,并返回一个错误。instagram页面的“脚本”似乎没有正确加载到heroku上Node.js Instagram Scraper在本地运行,但不在Heroku上运行,node.js,heroku,https,request,instagram,Node.js,Heroku,Https,Request,Instagram,我用这个脚本在Instagram上抓取一个用户页面。当我在本地运行它时,运行良好,我得到了包含我需要的信息的JSON。但当我部署到Heroku时,我无法正常运行,并返回一个错误。instagram页面的“脚本”似乎没有正确加载到heroku上 const request = require('request-promise'); const cheerio = require('cheerio'); /* Create the base function to be ran */ const
const request = require('request-promise');
const cheerio = require('cheerio');
/* Create the base function to be ran */
const start = async () => {
/* Here you replace the username with your actual instagram username that you want to check */
const USERNAME = 'doarda';
const BASE_URL = `https://www.instagram.com/${USERNAME}/`;
/* Send the request and get the html content */
let response = await request(
BASE_URL,
{
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'en-US,en;q=0.9,fr;q=0.8,ro;q=0.7,ru;q=0.6,la;q=0.5,pt;q=0.4,de;q=0.3',
'cache-control': 'max-age=0',
'upgrade-insecure-requests': '1',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36'
}
);
/* Initiate Cheerio with the response */
let $ = cheerio.load(response);
console.log("res")
console.log(response)
/* Get the proper script of the html page which contains the json */
let script = $('script').eq(4).html();
console.log("script")
console.log(script)
/* Traverse through the JSON of instagram response */
let { entry_data: { ProfilePage : {[0] : { graphql : {user} }} } } = JSON.parse(/window\._sharedData = (.+);/g.exec(script)[1]);
/* Output the data */
// console.log(user);
debugger;
}
但当我在Heroku上运行时,它返回错误:
at start (/app/igbot.js:32:128)
2020-10-17T13:43:49.171744+00:00 app[worker.1]: (node:4) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
出什么事了?代码中有问题或Instagram站点不支持heroku访问