How with use node.js get information from this tag that in page source - {{= flyingStatus(it.m_status) }}?

对着背影说爱祢 提交于 2020-01-06 08:26:15

问题


If I look page source, I see "unusual" attribute value:

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

Usually for me this is:

class = "value"

After loaded page, if I use button "Inspect", I see:

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

Now question, how get information with use Node.js from this "unusual" attribute value, if I use cheerio (jquery), but see nothing??? For example:

 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
        }
})

Moreover, on page use cloudflare's anti-ddos protection, may be this is important.


回答1:


So, on page you have:

<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>

And you want see all information. Code for that with use node.js and 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();
})();

more informationt there: https://github.com/GoogleChrome/puppeteer/issues/1897



来源:https://stackoverflow.com/questions/48367798/how-with-use-node-js-get-information-from-this-tag-that-in-page-source-fly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!