简体   繁体   中英

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)
  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.

You have set timer interval to 5000 milliseconds which makes it 5 seconds only. So your code will run every 5 seconds. If you want to run your timer every minute, you should set it to 1000x60=60000 ms. I hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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