2011-02-15 70 views
1

我是一个相对较新的编码器,并已逛了一下就到这里,并在谷歌前问搜索,但我已经想出空。可能会刷新网站,直到用Javascript更改?

我想知道是否有创造的Javascript说脚本的方式,并将它刷新页面,直到有页面上的变化通过输入页面为一个字符串。

东西线沿线的(原谅索迪伪代码,但我知道有些功能需要解决此写入):

Start 

currentPage = webclient.getPage("www.somesite.com") 
boolean diff = false 
string pageText = currentPage.astext() 

do { 
    currentPage.refresh() 
} until (currentPage.astext() != pageText) 

string alert = "Change Found" 
string address = "[email protected]" 
e-mail(address,alert) 

END 

感谢所有帮助任何人都可以提供这个新的编码器:)

+3

我不知道要得到完全你想要什么,但看起来JavaScript并不是你需要的语言。你最好使用PHP或Perl,JavaScript不能发送邮件。 – BiAiB 2011-02-15 17:05:13

回答

1

PHP似乎更适合这种操作。这里是我会做什么:

  • 抓取网页内容与卷曲
  • 等一等(如1分钟)*
  • 抓取网页内容再一次
  • 比较两者的页面内容
  • Ë邮件,如果有变化,无论如何开始

*你不想刷新页面,因为你的伪代码,因为你的脚本会吃很多bandwidt h,并且很可能会让您的目标网站饱和。

你需要的代码示例?

编辑
这里是我工作的PHP脚本:

<?php 
//////////////// 
// Parameters // 
//////////////// 
$url = 'http://www.example.com'; 
$sleepyTime = 60; // seconds 
$recipient = '[email protected]'; 
$subject = 'Change found'; 
$message = 'Change found in ' . $url; 

//////////////// 
// Functions // 
//////////////// 
function fetchWebsiteContent($url) { 
    // init curl handle 
    $ch = curl_init($url); 

    // Tells curl to return the content 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

    // fetch content 
    $res = curl_exec($ch); 

    // close handle and return content 
    curl_close($ch); 
    return $res; 
} 

//////////////////// 
// The comparison // 
//////////////////// 
$firstContent = fetchWebsiteContent($url); 

// This is an endless checking scope 
while (1) { 
    // sleep a bit and fetch website content again 
    sleep($sleepytime); 
    $secondContent = fetchWebsiteContent($url); 

    // check if change occured 
    if ($firstContent == $secondContent) { 
     mail($recipient, $subject, $message); 
    } 

    $firstContent = $secondContent; 
} 
?> 

帮助ressources:
cURL manual
mail manual

希望你喜欢它;)

+0

谢谢各位男士,感谢您对羽翼未丰的先行者的帮助!另外一个代码示例会让我很开心! 并且关于刷新率,我的负载测试工作一个网站,目的是不要让用户进入站点,直到有人从另一端,用户将达到超时,直到进入系统。我是新来的这个项目和一个相对较新的编码器,所以我想自动化我们如何测试它以贡献更多! :) – 2011-02-16 10:02:08