首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >pinterest网络擦伤图像

pinterest网络擦伤图像
EN

Stack Overflow用户
提问于 2022-05-01 23:04:45
回答 1查看 217关注 0票数 1

我试图从pinterest图像中获取一个url,并通过pinterest上用户的一般配置文件发送它的一个url,但它正在返回未定义的我

我的代码:

代码语言:javascript
复制
const Command = require("../../structures/Command");
const cheerio = require("cheerio");
const rp = require("request-promise");
const { head } = require("request");

module.exports = class Pinterest extends Command {
  constructor(client) {
    super(client);
    this.client = client;

    this.name = "pinterest";
    this.category = "Dono";
    this.aliases = [];

    this.enabled = true;
    this.guildOnly = true;
  }
  async run({ message, args, prefix, author }, t) {
    if (
      message.author.id !== "196679829800747017"
    )
      return;

      const URL = (`https://br.pinterest.com/n1cotin3/_created/`)
      const headerObj = {
          uri: URL
      };
      rp(headerObj)
      .then(html => {
          var $ = cheerio.load(html)

          const avatar = $("#mweb-unauth-container > div > div:nth-child(2) > div:nth-child(3) > div.F6l.ZZS.k1A.zI7.iyn.Hsu > div > div > div > div:nth-child(1) > div:nth-child(1) > div > div > div > div > div > a > div > div > div > div > div.XiG.zI7.iyn.Hsu > img").attr("src")
          console.log(avatar)
    message.react(``);
  })
}
};
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-05-01 23:31:02

问题是页面仍然在加载。#mweb-unauth-container > div > div:nth-child(2)不存在,因为#mweb-unauth-container > div只有一个div子元素,而且它是一个加载图标。我不认为这是你可以做的事,与欢呼,你将不得不使用一个替代方案,可以解决Javascript (如Puppeteer)。

或者,如果您不想刮,您可以使用一个私有API (尽管它在任何时候都可能发生变化,但肯定会更好地执行):

https://widgets.pinterest.com/v3/pidgets/users/n1cotin3/pins/

示例:

代码语言:javascript
复制
const res = await requestThatEnpointSomehow();
const images = res.data.pins.map(({ images }) => images['564x']);

// `images` will be a list of URLs.
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72081013

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档