Hi,
The class
WebRequest allow that you get the html of the site (source code).
The html, you can read your tags with the
HtmlAgilityPack library.
Link:
Html Agility Pack | HAP
Here, the code for read html of the site:
private HtmlAgilityPack.HtmlDocument GetWebSiteContents(string url)
{
string postString = "";
HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(new Uri(url));
WebReq.Method = "POST";
WebReq.ContentType = "application/x-www-form-urlencoded";
WebReq.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
WebReq.ContentLength = postString.Length;
StreamWriter requestWriter = new StreamWriter(WebReq.GetRequestStream());
requestWriter.Write(postString);
requestWriter.Close();
Stream stream = WebReq.GetResponse().GetResponseStream();
HtmlAgilityPack.HtmlDocument htmldoc = new HtmlAgilityPack.HtmlDocument();
htmldoc.Load(stream);
stream.Close();
WebReq.GetResponse().Close();
return htmldoc;
}
IMPORTANT! If the site have authentication, you need send the authentication cookie.
....
HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(url);
WebReq.CookieContainer = new CookieContainer();
WebReq.CookieContainer.SetCookies(url, enter here the authentication cookie);
....
To read the html tag elements:
HtmlAgilityPack.HtmlDocument html = null;
HtmlNode[] elems = null;
html = this.GetWebSiteContents(url);
elems = html.DocumentNode.Descendants("input").Where(n => n.Attributes["name"] != null && n.Attributes["name"].Value == "name_html_tag").ToArray();
string myvalue = elems[0].Attributes["value"].Value.ToString();