Home Ask Login Register

Developers Planet

Your answer is one click away!

Răzvan Bălan February 2016

Search for certain string in InnerHtml file using webbrowser

I am a beginner in c# and i don't seem to manage to scrap an innerHtml from a website. The website is a ticket management system which has tickets entered by ID. After entering the ID, i would like some information to be displayed in a Windows form application textboxes: ticket title, created at, and so on..

Untill now, I used webbrowser in order to log in on the site and then i want to enter a ticket ID into a textbox and after pressing Generate button i want to display the ticket title into a textbox.

Here is my code: // for the log in button


            while (this.webBrowser1.ReadyState != WebBrowserReadyState.Complete)

            //textBox1.Text= this.webBrowser1.Document.Window.Frames[2].Document.GetElementsByTagName("input").Count.ToString();

            this.webBrowser1.Document.Window.Frames[2].Document.GetElementsByTagName("input")[0].InnerText = textBox1.Text;
            this.webBrowser1.Document.Window.Frames[2].Document.GetElementsByTagName("input")[1].InnerText = textBox2.Text;

// for the generate button

    this.webBrowser1.Navigate("https://elvis.harman.com/cgi-bin/ticket?TID=" + txtID.Text);
var codes = this.webBrowser1.Document.GetElementById("field_100").InnerHtml.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Select(m => m.Trim()).ToList(); 
// with this i tried to separate the innerHtml by lines

//and now i try to start scrapping beggining with a following line:
 var ticketLines = codes.Where(m => m.StartsWith("<TD style=\"WIDTH: 65px; HEIGHT: 22px; LEFT: 110px\" class=hb-table-cell>"));


Răzvan Bălan February 2016

I managed to solve this and i will post it here so that this post should have a reason :)

foreach (string line in ticketLines)
                if (line.Contains(searchkeys)) 
                    //daca se gaseste ce e in txtID se ia indexul liniei si il bag in txtTitle.text
                    int y = codes.IndexOf(line);
                    txtTitle.Text = codes[y+1].Substring(codes[y + 1].IndexOf(">") + 1, codes[y + 1].Length - codes[y + 1].IndexOf(">") - 6);
                    txtCreatedAt.Text = codes[y + 3].Substring(codes[y + 3].IndexOf(">") + 1, codes[y + 3].Length - codes[y + 3].IndexOf(">") - 6);
                    txtCreatedBy.Text = codes[y + 4].Substring(codes[y + 4].IndexOf(">") + 1, codes[y + 4].Length - codes[y + 4].IndexOf(">") - 6);



Post Status

Asked in February 2016
Viewed 1,043 times
Voted 14
Answered 1 times


Leave an answer

Quote of the day: live life