如何使用类名从Web页面获取特定标记的innertext [英] How to get innertext of particular tag from web page by using Class name

查看:111
本文介绍了如何使用类名从Web页面获取特定标记的innertext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我希望通过使用类名来获取网页中特定标记的内容...如www.google.com或www.wikipedia.com等网址。



为此,我使用下面的代码(HtmlAgilityPack)...



Hi,
I want to get innertext of particular tag from web page by using class name...url like www.google.com or www.wikipedia.com etc.

For this i used below code(HtmlAgilityPack)...

            string url = string.Empty;
            url = TextWeburl.Text;

            HtmlDocument htmlDoc = new HtmlDocument();
            htmlDoc.LoadHtml(url);
//            XPathNavigator docNav = htmlDoc.CreateNavigator();

//            XPathNavigator node = docNav.SelectSingleNode("//p");

            string name = htmlDoc.DocumentNode.SelectSingleNode("//p/span").Attributes["theGood"].Value;





但字符串中的空值为...



是有没有更好的方法来解决这个问题???



but it takes null value in string...

is there any better way to solve this issue???

推荐答案

嗨Balasubramanian,

我建议你通过以下链接它们为您提供了从给定URL读取值以获取网站标题和描述的想法。您还可以使用此引用通过类名和您指定的URL获取innertext或value。



http://blogs.msdn.com/b/ noahc / archive / 2007/02/19 / get-a-web-page-s-title-from-a-url-c.aspx [ ^ ]

http://www.c-sharpcorner.com/UploadFile/c63ec5/get-title-and-meta-description-of-live-url/ [ ^ ]
Hi Balasubramanian,
I would recommend you to go through the following links as they give you the idea of reading the value from a given url to get the Title and Description of the website. You could also make use of this reference for taking the innertext or value by classname with the url you specify.

http://blogs.msdn.com/b/noahc/archive/2007/02/19/get-a-web-page-s-title-from-a-url-c.aspx[^]
http://www.c-sharpcorner.com/UploadFile/c63ec5/get-title-and-meta-description-of-live-url/[^]


这篇关于如何使用类名从Web页面获取特定标记的innertext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆