本地刮板和云刮板返回不同的结果

时间:2020-08-31 22:16:30

标签: javascript node.js google-cloud-functions instagram puppeteer

我尝试抓取instagram并获得不同的结果。功能正在通过下面的命令进行部署。当我从此视频尝试非常类似的功能时:https://www.youtube.com/watch?v=i8THvr03FaY&list=WL&index=54&t=0s 一切正常。 instagram imo似乎有问题,但也许有人知道如何解决此问题。

我的抓取代码段:

const puppeteer = require('puppeteer');

let browserPromise = puppeteer.launch({
  args: ['--no-sandbox'],
});

exports.igprof = async (req, res) => {
  const username = req.query.username || 'instagram';
  let url = 'https://www.instagram.com/' + username;

  const browser = await browserPromise;
  const context = await browser.createIncognitoBrowserContext();
  const page = await context.newPage();

  await page.goto(url, { waitUntil: 'networkidle2' });
  const html = await page.evaluate(() => document.body.innerText);
  //   const json = JSON.parse(html);

  //   if (json.graphql) {
  //     console.log(json.graphql.user.profile_pic_url_hd);
  //     await page.goto(json.graphql.user.profile_pic_url_hd);
  //   }

  const image = await page.screenshot({
    clip: {
      x: 240,
      y: 140,
      width: 320,
      height: 320,
    },
  });

  //   res.setHeader('Content-Type', 'image/png');
  res.setHeader('Content-Type', 'text/html');
  //   res.send(image);
  res.send(html);

  context.close();
};

package.json

{
  "name": "ig-prof",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "functions-framework --target=igprof"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@google-cloud/functions-framework": "^1.2.1",
    "puppeteer": "^1.19.1"
  }
}

部署命令:

gcloud functions deploy igprof --trigger-http --runtime=nodejs10 --memory=1024mb --region=europe-west1

结果为本地主机:

instagram Verified Follow 6,462 posts 362m followers 59 following Instagram #ShareBlackStories about.instagram.com/blog/announcements/introducing-instagram-reels-announcement Made Us ? Guides ? Reels ⭐️ #TryThisAtHome SBS ? Pride 2020 ? Juneteenth Self-Care Tips 2020 Vision POSTS GUIDES IGTV TAGGED Show More Posts from instagram Related Accounts See All virat.kohli Verified Virat Kohli Follow billieeilish Verified BILLIE EILISH Follow championsleague Verified UEFA Champions League Follow marshmellomusic Verified marshmello Follow carryminati Verified ???? ????? Follow sachintendulkar Verified Sachin Tendulkar Follow tiktok Verified TikTok Follow nickiminaj Verified Barbie Follow leonardodicaprio Verified Leonardo DiCaprio Follow samsungwithgalaxy Verified Samsung #withGalaxy Follow sony Verified Sony Follow To help personalize content, tailor and measure ads, and provide a safer experience, we use cookies. By clicking or navigating the site, you agree to allow our collection of information on and off Instagram through cookies. Learn more, including about available controls: Cookies Policy. Close Search Log In to Instagram Log in to see photos and videos from friends and discover other accounts you'll love. Log In Sign Up Log In Sign Up ABOUTHELPPRESSAPIJOBSPRIVACYTERMSLOCATIONSTOP ACCOUNTSSUGGESTED ACCOUNTSHASHTAGSLANGUAGE Afrikaans Čeština Dansk Deutsch Ελληνικά English Español (España) Español Suomi Français Bahasa Indonesia Italiano 日本語 한국어 Bahasa Melayu Norsk Nederlands Polski Português (Brasil) Português (Portugal) Русский Svenska ภาษาไทย Filipino Türkçe 中文(简体) 中文(台灣) বাংলা ગુજરાતી हिन्दी Hrvatski Magyar ಕನ್ನಡ മലയാളം मराठी नेपाली ਪੰਜਾਬੀ සිංහල Slovenčina தமிழ் తెలుగు Tiếng Việt 中文(香港) Български Français (Canada) Română Српски Українська © 2020 INSTAGRAM FROM FACEBOOK

产生Google Cloud

Instagram Phone number, username, or email Password Log In OR Log in with Facebook Forgot password? Don't have an account? Sign up Get the app. ABOUTHELPPRESSAPIJOBSPRIVACYTERMSLOCATIONSTOP ACCOUNTSHASHTAGSLANGUAGE Afrikaans Čeština Dansk Deutsch Ελληνικά English Español (España) Español Suomi Français Bahasa Indonesia Italiano 日本語 한국어 Bahasa Melayu Norsk Nederlands Polski Português (Brasil) Português (Portugal) Русский Svenska ภาษาไทย Filipino Türkçe 中文(简体) 中文(台灣) বাংলা ગુજરાતી हिन्दी Hrvatski Magyar ಕನ್ನಡ മലയാളം मराठी नेपाली ਪੰਜਾਬੀ සිංහල Slovenčina தமிழ் తెలుగు Tiếng Việt 中文(香港) Български Français (Canada) Română Српски Українська © 2020 INSTAGRAM FROM FACEBOOK

为什么会返回不同的结果,我该如何解决?

0 个答案:

没有答案