本文介绍了如何使用类名从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???

推荐答案


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

10-20 12:43