How to track changes on a website?

So, I’ve been working on this for a month, but I haven’t found anything on the network, so although it’s possible that every minute you can check the changes in the source code of websites, it seems that the source code changes every second, so are there any Is there any problem in my coding or is there another way to track website changes?

here is 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!"); } } } 
+4
source share
2 answers

Firstly, I would suggest that when you need to compare the actual content of a page with a saved version, you:

  • Compare the MD5 hash code that you saved against the hash of the new one (and not the contents each time)
  • Remember that the page changes elements that you may not consider when changing the content of the page ...

Some servers return a Last-Modified header, which you can use for comparison, I think.

+1
source

You set the timer interval to 5000 milliseconds, which is 5 seconds. This way your code will run every 5 seconds. If you want to start your timer every minute, you must set it to 1000x60 = 60,000 ms. Hope this helps.

0
source

Source: https://habr.com/ru/post/1484777/


All Articles