Reputation: 646
i want to know methods of caputring the html Content which is displayed on the Web browser in C# application .. i used HTML Agility pack initally . if my knowledge is true my coding below
htmlWeb hw = new HtmlWeb();
if (txtCurrentURL.Text == "")
{
MessageBox.Show(" Enter Web Address to Process ");
}
else
{
HtmlAgilityPack.HtmlDocument htmlDoc = hw.Load(@txtCurrentURL.Text);
if (htmlDoc.DocumentNode != null)
{
try
{ foreach (HtmlNode text in htmlDoc.DocumentNode.SelectNodes(txtExpression.Text))
{
_items.Add(text.InnerHtml);
richTextResults.Text = text.InnerHtml;
} }
catch
{ MessageBox.Show(" No Usefull Data found");
}
lstBxResult.DataSource = _items;
}
}
and
txtCurrentUR.Text
is the url address which My Web browser currenlty Displayed .
If I AM not wrong , the Result from HTMLAgility is a result which we got by connecting to the mentioned URL using HTMLagility Class and not by accessing the web server Content, am I right ??? . So my problem is that if page requires any login or pages accessed only after login like inbox, user Account page are not showing error in the Agility . but as we now that in web browser we can display these easily and i want to capture data which is displayed on the browser not by connecting the URl and capture the data using Agility ... but I don't know how to do it please help me ??
Upvotes: 2
Views: 875
Reputation: 507
If I understand correctly, what your going to want to use is the Cookies collection.
private HtmlWeb CreateWebRequestObject()
{
HtmlWeb web = new HtmlWeb();
web.UseCookies = true;
web.PreRequest = new HtmlWeb.PreRequestHandler(PreRequestStuff);
web.PostResponse = new HtmlWeb.PostResponseHandler(AfterResponseStuff);
web.PreHandleDocument = new HtmlWeb.PreHandleDocumentHandler(PreHandleDocumentStuff);
return web;
}
Upvotes: 1