簡體   English   中英

使用 Node JS 從 Telegram Web 頁面中提取所有 HTML 元素

[英]Extract all HTML elements from Telegram Web page with Node JS

我想從 Telegram web 網站中提取所有 HTML 元素。 我嘗試了所有方法,例如 get、post、get() jquery,來自 Python、JavaScript 的方法,...

但是當他們返回結果時,它是不完整的,並且其中的某些部分丟失了。 我怎樣才能正確地做到這一點?

這是一個返回不完整元素的片段:

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

試試這個方法

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

結帳 jsdom 文檔: https://github.com/jsdom/jsdom

您是否嘗試添加 header:"Application-Type":"text/html"

我了解到 Telegram Web 抓取,我們不能使用傳統的 javascript 代碼或簡單的 Python 庫。 在這種情況下,我們必須使用 Selenium 和 WebDriver,我正在研究它。 任何更好的建議將不勝感激。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM