WE ARE SHARING
OUR EXPERIANCE.
BELIEVE THE POWER OF SHARE
BLOG
Triggering Buttons in C # with Html and Reading Data
First of all, we open Visual Studio for this process and create a Windows Form project. We add WebBrowser, Button and Timer from Toolbox. We use HttlAgilityPack when we parse the html backwards. We keep track of the Tools> Nuget Package Manager> Package Manager Console for the installation. We install the HmtlAgilityPack with the command "Install-Package HtmlAgilityPack" in the popup console. Now we need to open the HTML page which we will export on the WebBrowser to the Form Load Event We are writing the code
"WebBrowser1.Navigate (" http://manta.com.tr/ ");"
If we just want to read the data in HTML, click the button
"Var Data = WebBrowser1.Document.Body.InnerHtml;" is enough to write the code.
If we want to access the HTML object we want from Data, we need to use HtmlAgilityPack that we have created with the help of Nuget Package. using HtmlAgilityPack; We can not add namespace to our code.
var htmlDoc = new htmlagilitypack.htmldocument ();
htmldoc.loadhtml (Data);
var cells = htmlDoc.DocumentNode.SelectNodes ("// table [@ role = 'grid'] /")[2];
This code block gives us the HTML code with the role attribute value grid from the tables in the HTML, so if you have more than one table providing this status in the HTML ([2]) as in the example code,If we want to trigger a Button in the HTML, an object like Linkie Yada, we need to find this object first. The 'InvokeMember' code then allows us to trigger the object.
WebBrowser1.document.all[ "nesneninıds for"]. InvokeMember ( "click");
or
HtmlElement Btn= WebBrowser1.Document.All ["objectInstance"];
object obj = Btn.DomElement;
object [] arg = {};
System.Reflection.MethodInfo mi = obj.GetType (). GetMethod ("click");
var Method = mi.Invoke (obj, arg);
The code also performs the same function. The code performs the change in the HTML after a certain period of time. After we write this code, we want to draw the object in the bottom line in the HTML
"Var Data = WebBrowser1.Document.Body.InnerHtml;"
We get the previous HTML data from the "click" function. If we want to get the data after the "click" function, we have to write this code in the Timer. For example, after the "click" function, there is an object named "newID" in the HTML page that will be newly loaded. We can check it in Timer to check if our new HTML page is created.
"Var Data = WebBrowser1.Document.Body.InnerHtml;"
If(WebBrowser1.Document.All ["newID"]! =null && Browser.Document.Body.InnerHtml.Contains ("newID"))
{...}
After this condition in Timer, pull the newly formed HTML data. We can continue to do similar functions.
HtmlAgilityPack related documentation can be found at http://html-agility-pack.net/documentation.