Javascript 使用bookmarklet检索动态生成的HTML
我正在制作一个书签,用文章中的评论替换网站上新闻文章的标题。我编写了一些代码,可以查找所有链接、访问文章并查找评论:Javascript 使用bookmarklet检索动态生成的HTML,javascript,jquery,html,screen-scraping,bookmarklet,Javascript,Jquery,Html,Screen Scraping,Bookmarklet,我正在制作一个书签,用文章中的评论替换网站上新闻文章的标题。我编写了一些代码,可以查找所有链接、访问文章并查找评论: javascript:(function() { $("h1,h2,h3,p").each(function() { //loops through all the h1, h2, and h3 elements var link = $(this).find('a');//creates a variable for the a element
javascript:(function() {
$("h1,h2,h3,p").each(function() { //loops through all the h1, h2, and h3 elements
var link = $(this).find('a');//creates a variable for the a element
var url = $(this).find('a').attr("href");//creates a variable for the link attribute
$.get(url, function(data) {//goes to each link
var comments = $(data).find("#commentsDiv-comments");//finds the comments
if ($(comments).length) {//if comments length exists, return comments
$(link).html(comments);
} else {
$(link).html("No comments");//otherwise, return "no comment"
}
});
});
})();
问题是,注释html是由一个脚本生成的,在MyBookmarklet访问文章的html之前,这个脚本没有运行。正因为如此,我的bookmarklet找不到任何评论,它对每一篇文章都返回“无评论”
我在stackoverflow上看到了一些关于这方面的答案,但所有这些答案似乎都需要其他库等,我不知道如何在bookmarklet中使用这些库。有人能帮我解决这个问题吗?在执行刮片之前,你能触发加载注释所需的脚本吗?我对此进行了研究,但我不确定如何进行。