简体   繁体   English

如何监控网站的变化?

[英]How to monitor changes in a website?

So I've been working on this for a month but I found nothing on the net so I though that it might be possible to check changes in websites source code every minute but it seems it's source code is changing every second, so is there any problem in my coding or is there any other way to monitor a website's changes? 所以我已经在这个工作了一个月,但我在网上什么都没发现,所以我觉得每分钟检查一下网站源代码的变化是可能的,但似乎它的源代码每秒都在变化,所以有没有我的编码问题还是有其他方法来监控网站的变化?

here's my code: 这是我的代码:

private void Startbtn_Click(object sender, EventArgs e)
   {

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.google.com");                            
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader source = new StreamReader(response.GetResponseStream());
richTextBox1.Text = source.ReadToEnd();
timer1.Start();
timer1.Interval = 60000;

     }

private void timer1_Tick(object sender, EventArgs e)
    {

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.google.com");
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        StreamReader source2 = new StreamReader(response.GetResponseStream());
        RichTextBox checker = new RichTextBox();
        checker.Text = source2.ReadToEnd();
        if (richTextBox1.Text == "")
        {
            richTextBox1.Text = checker.Text;

        }
        else
        {


            if (richTextBox1.Text != checker.Text)
            {
                MessageBox.Show("somthing changed");
                richTextBox1.Text = checker.Text;
            }
            else
            {
                MessageBox.Show("No changes yet!");

            }
        }
    }

Firstly I would suggest that when have to compare the actual contents of a page to a stored version you: 首先,我建议在必须将页面的实际内容与存储的版本进行比较时:

  1. Compare a MD5 hash you've stored against the hash of the new one (not the contents everytime) 将您存储的MD5哈希值与新哈希值的哈希值进行比较(不是每次都是内容)
  2. Remember that there are changing elements in a page that you may not regard as the page content changing... 请记住,页面中存在更改元素,您可能不会将其视为页面内容更改...

Some servers will return a Last-Modified header which you could use to do a compare i guess. 一些服务器将返回Last-Modified标头,您可以使用它来进行比较。

You have set timer interval to 5000 milliseconds which makes it 5 seconds only. 您已将计时器间隔设置为5000毫秒,这使其仅为5秒。 So your code will run every 5 seconds. 所以你的代码将每5秒运行一次。 If you want to run your timer every minute, you should set it to 1000x60=60000 ms. 如果要每分钟运行一次计时器,则应将其设置为1000x60 = 60000 ms。 I hope this helps. 我希望这有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM