3

有人有一个如何从 Web GUI 调用 scrapyd 的示例?

我想从 web GUI 调用 Scrapy 来实现 web Crawler 。

我找到了这个例子,但对我不起作用:

http://mahmoud.abdel-fattah.net/2012/07/04/super-simple-and-basic-scrapyd-web-interface/

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Simple scrapyd web manager</title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
        <script type="text/javascript">

            var scrapyd_url = 'http://localhost:6800/';

            var project_name = 'bkam';

            var all_spiders = new Array();
            var running_spiders = new Array();
            var finished_spiders = new Array();

            $(document).ready(function() {
                $(".start_spider").live('click', function() {
                    spider_name = $(this).attr('rel');
                    $.post(scrapyd_url + 'schedule.json', {
                        project : project_name,
                        spider : spider_name
                    });

                });

                $(".stop_spider").live('click', function() {
                    job_id = $(this).attr('rel');
                    $.post(scrapyd_url + 'cancel.json', {
                        project : project_name,
                        job : job_id
                    });

                });

                function listjobs() {
                    $.getJSON(scrapyd_url + 'listjobs.json?project=' + project_name, function(data) {
                        var finished_items = [];
                        $.each(data.finished, function(key, val) {
                            finished_spiders.push(val.spider);
                            finished_items.push('<li>' + val.spider + '&nbsp;&nbsp;<a href="' + scrapyd_url + 'logs/' + project_name + '/' + val.spider + '/' + val.id + '.log">log</a></li>');
                        });
                        $('#finished_spiders').append(finished_items.join(''));

                        if (data.running.length > 0) {
                            var running_items = [];
                            $.each(data.running, function(key, val) {
                                running_spiders.push(val.spider);
                                running_items.push('<li>' + val.spider + '&nbsp;&nbsp;<a href="' + scrapyd_url + 'logs/' + project_name + '/' + val.spider + '/' + val.id + '.log">log</a>&nbsp;&nbsp|&nbsp;&nbsp<a href="#" class="stop_spider" rel="' + val.id + '">Stop</a></li>');
                            });
                            $('#running_spiders').append(running_items.join(''));
                        } else {
                            $('#running_spiders').append('<li>No Running spiders</li>');
                        }

                    });
                }

                listjobs();

                // Get spiders list
                $.getJSON(scrapyd_url + 'listspiders.json?project=' + project_name, function(data) {
                    var items = [];
                    //console.log(data);
                    $.each(data.spiders, function(key, val) {
                        items.push('<li id="' + val + '">' + val + '&nbsp;&nbsp;<a href="#" class="start_spider" rel="'+ val + '">Start</a></li>');
                    });

                    $('#available_spiders').append(items.join(''));
                });

            });
        </script>
    </head>
    <body>
        <a href="#" onClick="window.location.reload">refresh</a>
        <br />
        List of running spiders
        <ul id="running_spiders"></ul>
        List of finished spiders (First is latest)
        <ul id="finished_spiders"></ul>
        List of available spiders
        <ul id="available_spiders"></ul>
    </body>
</html>

我想从 web gui 运行蜘蛛点击按钮。请帮我 ... :(

4

1 回答 1

0

据我所知,此示例尝试联系我认为您没有运行的scrapyd 。

如果您确定它正在运行,请尝试在浏览器中访问http://localhost:6800/- 它应该会返回一些内容。

于 2012-07-11T04:11:13.887 回答