【发布时间】:2020-02-15 11:41:24
【问题描述】:
我想从 Chrome 扩展中的 url 下载页面的源代码。
我有这样的东西。但不知道如何将文本格式化为html。 或者如果这种格式有效,如何在控制台中显示源代码。
fetch('https://www.transfermarkt.com/robert-lewandowski/profil/spieler/38253').then(r => r.text()).then(result => {
// Result now contains the response text, do what you want...
console.log("Fetch result: " + result);
var parser = new DOMParser();
var source_code = parser.parseFromString(result, "text/html");
console.log("Source code: " + source_code);
});
例如,我想从跨度“dataValue”中获取文本。 我怎样才能做到这一点?
【问题讨论】:
-
@mplungjan 那么如何使用 getElementByClass 或其他东西从中获取一些东西。
-
看我的回答......
标签: javascript html dom google-chrome-extension