1
我怎么能在字符串ID或类找到HTML元素?(正则表达式,C#)查找ID或类元素串
<div class="item1">content</div>
<div class="item2">content</div>
只得到
<div class="item1">
我怎么能在字符串ID或类找到HTML元素?(正则表达式,C#)查找ID或类元素串
<div class="item1">content</div>
<div class="item2">content</div>
只得到
<div class="item1">
如果你想利用只有格 - 试试这个
<div (class|id)="myClassNameOrId".*?>
而不是myClassNameOrId
输入您自己的类或id名称。 如果您需要其他元素 - 将div
替换为其他标签的名称。
使用[HTML Agility Pack](http://htmlagilitypack.codeplex.com/)和[不要使用正则表达式](http://stackoverflow.com/questions/1732348/regex-match-open-tags -except-xhtml-self-contained-tags) – Habib
你不想使用XmlDocument或XDocument而不是正则表达式的任何原因? –
除非您确定传入的HTML具有不会更改的一致格式,[正则表达式对于分离HTML来说是一个糟糕的解决方案](http://stackoverflow.com/a/1732454/1583)。正如@Habib所评论的,为此使用HAP。 – Oded