Home > OS >  Extract all HTML elements from Telegram Web page with Node JS
Extract all HTML elements from Telegram Web page with Node JS

Time:08-29

I want to extract all HTML elements from Telegram web website. I tried all methods e.g. get, post, get() jquery, methods from Python, JavaScript, ...

But when they return the result, it is incomplete and some part of it is missing. How can I do this correctly?

This a snippet that returns an incomplete alements:

fetch("https://web.telegram.org/k/")
  .then(x => x.text())
  .then(y => console.log(y));

CodePudding user response:

try this way,

// first install jsdom
// type npm i jsdom in the console.

const jsdom = require("jsdom");
const { JSDOM } = jsdom;

fetch("https://web.telegram.org/k/")
    .then(x => x.text())
    .then(y => {
        const { document } = (new JSDOM(y)).window;
        console.log(document)
});

checkout jsdom documantation: https://github.com/jsdom/jsdom

CodePudding user response:

did you try to add header: "Application-Type" :"text/html"

  • Related