开发者

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

开发者 https://www.devze.com 2023-03-05 07:42 出处:网络
There are many times I need to extract value of an element from a HTML page. Something like this: <!-- many html here -->

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

精彩评论

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