开发者

capture web browser diplayed page HTML Source using HTMLAgility

开发者 https://www.devze.com 2023-03-20 03:34 出处:网络
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

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))
        开发者_Python百科            {
                        _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 ??


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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号