ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Other Software > Developer's Corner

[Help] - Check if a webpage contains some text then do something (C#)

(1/2) > >>

KynloStephen66515:
Actually going to pull my hair out if I can't work this out lol

Trying to work out how the hell to check if a webpage contains a certain string of text, and if it does, then do something (I know how to get it to do something afterwards...just can't work out how to CHECK)

In non-code, this would be:

if webPage.ContainsString("No Messages Found") {  //Do Something } else { //Do Something Different }

Bit vague on this I know, I suck at explaining these things :(

Ath:
You can use a webbrowser control to fetch the page, then check its content with a regex.

KynloStephen66515:
You can use a webbrowser control to fetch the page, then check its content with a regex.
-Ath (September 07, 2014, 03:33 PM)
--- End quote ---

I was already using a webBrowser control and was looking into using the HTML Agility Pack I got off NuGet to do this, but it is seeming like a pain in the ass...Also..I suck BADLY with Regex lol

Renegade:
I was already using a webBrowser control and was looking into using the HTML Agility Pack I got off NuGet to do this, but it is seeming like a pain in the ass...Also..I suck BADLY with Regex lol
-Stephen66515 (September 07, 2014, 03:39 PM)
--- End quote ---

You need to decide on which control you will use. I'll use the stock control here.


--- Code: C# ---private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)        {            if (webBrowser1.DocumentText.Contains("No Messages Found")) {                this.Text = "No Messsaged Found found";            }        }
That is all you need.

Ath:
Also..I suck BADLY with Regex lol
-Stephen66515 (September 07, 2014, 03:39 PM)
--- End quote ---
There's a fix for that, reported here, in our DC forum :up:

Navigation

[0] Message Index

[#] Next page

Go to full version