【问题标题】:How with use node.js get information from this tag that in page source - {{= flyingStatus(it.m_status) }}?如何使用 node.js 从页面源中的这个标签获取信息 - {{= flyStatus(it.m_status) }}?
【发布时间】:2018-01-25 09:28:55
【问题描述】:

如果我查看页面源代码,我会看到“不寻常”的属性值:

class = "bma-fly flying {{= flyingStatus(it.m_status) }}

对我来说通常是这样的:

class = "value"

加载页面后,如果我使用“检查”按钮,我会看到:

class = "bma-fly flying flying-won-team2 flying-past"

现在的问题,如果我使用cheerio(jquery),如何从这个“不寻常的”属性值中获取使用Node.js的信息,但什么也没看到??? 例如:

 request(link, function(err, resp, html) {
        if (!err){
          const $ = cheerio.load(html);
          let info = $("div.bma-fly.flying.flying-won-team2.flying-past");
          fs.writeFileSync("4.txt" , info); // nothing
        }
})

另外,在页面上使用cloudflare的反ddos保护,可能这很重要。

【问题讨论】:

  • ну пацаны ну вы чё
  • 你需要一些带有 javascript 的东西,比如 jsdom 或 puppeteer。
  • 谢谢,我会研究这个图书馆
  • @pguardiario 我找到信息

标签: javascript jquery node.js cloudflare cheerio


【解决方案1】:

所以,在页面上你有:

<div class = "bma-fly flying flying-won-team2 flying-past"> la la la </div>
<div class = "bma-fly flying flying-won-team2 flying-past"> kyrlik kyrkik </div>
<div class = "bma-fly flying flying-won-team2 flying-past"> bo bo bo </div>
<div class = "bma-fly flying flying-won-team2 flying-past"> info </div>
<div class = "bma-fly flying flying-won-team2 flying-past"> privet chelovek </div>

您想查看所有信息。 使用 node.js 和 puppeteer 的代码:

const puppeteer = require('puppeteer');
var fs = require('fs');

var link = "www. IIpuBeT Dpyr . com";

(async () => {
  console.log("Get info");
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto(link);
   });
   const text = await page.evaluate(() => {
      return [...document.body.querySelectorAll('.bma-fly.flying.flying-won-team2.flying-past')]
               .map(element => element.innerText)
               .join('\n');
    });

  console.log(text);
  fs.writeFileSync("nameFile.txt" , text);
  browser.close();
})();

更多信息:https://github.com/GoogleChrome/puppeteer/issues/1897

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多