使用phantomjs

时间:2015-10-09 10:16:47

标签: javascript web-crawler phantomjs

我必须浏览网站上的所有页面并检查每个页面上的元素。这必须以递归方式发生,我选择使用PhantomJS。所以,我基本上在main.js中有这样/这样的代码:

var page = require('webpage').create();

var allUrls = [];

var pageCheck = function(url) {

    page.open(url, function(success) {

        page.evaluate(function(allUrls, nextPage) {

            // crawl all links, and if they are from this site .. 
            // add them to the allUrls array .. 

            // then check the page for the element .. 

            // and go to next eventual page .. 
            setTimeout(nextPage, 250);

        }, allUrls, nextPage);

    });

};

var nextPage = function() {

    var nextUrl = allUrls.unshift();
    if(nextUrl) pageCheck(nextUrl);

};

pageCheck('http://example.com/');

我用phantomjs main.js称呼它。

但我看到的消息是“无法找到变量......”#34;当我清除所有这些 - 我现在看到Can't find variable: pageCheck

我该怎么做? ...... PhantomJS范围的所有内容是什么? ......

1 个答案:

答案 0 :(得分:1)

我设法弄清楚了,感谢@ArtjomB:)

基本上,我的错误是我试图从<?php $req3 = "SELECT DISTINCT conversation_id,column_name FROM `conversation_chat` WHERE `user_to`='$userid1' ORDER BY conversation_id desc"; $query=mysql_query($req3); $num=mysql_num_rows($req3); $hy= mysql_fetch_array($req3); $convo = $hy['conversation_id']; if($num!=0){ $req4 = mysql_query("SELECT DISTINCT id,column_name FROM `chat` WHERE `to`='$userid1' AND `conversation_id`='$convo' ORDER BY id desc "); while($dn1 = mysql_fetch_array($req4)) { ?> <td><img alt="example image" src="avatar.png"> &nbsp; &nbsp; <a href="read?id=<?php echo $dn1['id']; ?>"><?php echo htmlentities($dn1['from'], ENT_QUOTES, 'UTF-8'); ?></a></td> <td><span class="label vd_bg-green append-icon"> <?php echo $dn1['subject']; ?></span></td> <td style="width:80px" class="text-right"> <strong><?php echo timeAgo($dn1['time']); ?></strong></td><td style="width:80px" class="text-right"> <?php echo '<a href="mdelete.php?id='. $dn1['id'] .'">Delete</a>'; ?></td> </tr> <?php }}else{ echo "No new messages";} ?> 调用全局内容,而我只能将其用于page.evaluate操作。所以我把代码更改为/这样的一个:

page
相关问题