Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用bookmarklet检索动态生成的HTML_Javascript_Jquery_Html_Screen Scraping_Bookmarklet - Fatal编程技术网

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中使用这些库。有人能帮我解决这个问题吗?

在执行刮片之前,你能触发加载注释所需的脚本吗?我对此进行了研究,但我不确定如何进行。