开发者

String manipluation, how to extract an HTML element value easily?

There are many times I need to extract value of an element from a HTML page. Something like this:

<!-- many html here -->
<input type="hidden" name=开发者_开发知识库"id" value="ExtractMe!">
<!-- many html here -->

How can extract the value easily?


Have a look at the HTMLAgility pack, it makes this type of task very easy and regex-free.


If you need to parse HTML within your C# application consider using HTMLAgilityPack from here http://htmlagilitypack.codeplex.com/


If you just want to pluck values you're probably best to parse this as XML. You have a choice of standard XML or LINQ.

have a look here or here for some examples.


Why don't you use regular expressions? This the MSDN Regular Expression Documentation, in there you can look for The section Extracting a Single Match or the First Match.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜