我需要使用javascript,以获得标题的网站主页,当我浏览该网站的一个子网址。
如果我在这个网址(https://www.washingtonpost.com/world/2022/04/02/russia-ukraine-war-news-putin-live-updates/),document.title
将是“俄罗斯-乌克兰战争新闻:实时更新-华盛顿邮报”,但我需要得到“华盛顿邮报:打破新闻,世界,美国,华盛顿新闻和分析”,它document.title
这个网址(https://www.washingtonpost.com)?
发布于 2022-04-02 11:40:20
var doc = document;
if(window.location.pathname != "/"){
var data = await fetch(window.location.protocol+'//'+window.location.host+'/')
var body = await data.text()
doc = new DOMParser().parseFromString(body,"text/html");
}
console.log(doc.title);
https://stackoverflow.com/questions/71717138
复制相似问题