在htm标签之间搜索c#

时间:2015-12-23 22:05:45

标签: c# html string tags

如何从html标签获取信息? 我想在html代码中搜索示例writeby和retrun结果

喜欢第一行

<th scope="row">Written&#160;by</th>

Adachitoka 得到这个WritenBy:Adachitoka    这是我的HTML代码:

<td colspan="2" style="text-align:center;background:#CCF; font-weight:bold;">Manga</td>
</tr>
<tr>
<th scope="row">Written&#160;by</th>
<td>Adachitoka</td>
</tr>
<tr>
<th scope="row">Published&#160;by</th>
<td><a href="/wiki/Kodansha" title="Kodansha">Kodansha</a></td>
</tr>
<tr>
<th scope="row">English publisher</th>
<td>
<div style="overflow:hidden; width:100%;">
<div style="width:1.5em; float:left;"><small><sup style="font-style:normal;"><a href="/wiki/Northern_America" title="Northern America">NA</a></sup></small></div>
<div style="margin-left:1.5em;"><a href="/wiki/Kodansha_Comics_USA" title="Kodansha Comics USA">Kodansha Comics USA</a></div>
</div>
</td>
</tr>
<tr>
<th scope="row">Demographic</th>
<td><i><a href="/wiki/Sh%C5%8Dnen_manga" title="Shōnen manga">Shōnen</a></i></td>
</tr>
<tr>
<th scope="row">Magazine</th>
<td><i><a href="/wiki/Monthly_Sh%C5%8Dnen_Magazine" title="Monthly Shōnen Magazine">Monthly Shōnen Magazine</a><br />
Monthly Shōnen Magazine +</i></td>
</tr>
<tr>
<th scope="row">Original run</th>
<td><span class="nowrap">December 6, 2010</span> – ongoing</td>
</tr>
<tr>
<th scope="row">Volumes</th>
<td>15 + 1 special <span class="noprint">(<a href="/wiki/List_of_Noragami_chapters" title="List of Noragami chapters">List of volumes</a>)</span></td>
</tr>
<tr>
<td colspan="2" style="text-align:center;background:#CCF; font-weight:bold;">Anime television series</td>
</tr>
<tr>
<th scope="row">Directed&#160;by</th>
<td>Kotaro Tamura</td>
</tr>
<tr>
<th scope="row">Written&#160;by</th>
<td>Deko Akao</td>
</tr>
<tr>
<th scope="row">Music&#160;by</th>
<td><a href="/wiki/Taku_Iwasaki" title="Taku Iwasaki">Taku Iwasaki</a></td>
</tr>
<tr>
<th scope="row">Studio</th>
<td><a href="/wiki/Bones_(studio)" title="Bones (studio)">Bones</a></td>
</tr>
<tr>
<th scope="row">Licensed&#160;by</th>
<td>
<div style="overflow:hidden; width:100%;">
<div style="width:1.7em; float:left;"><small><sup style="font-style:normal;"><a href="/wiki/Australasia" title="Australasia">AUS</a></sup></small></div>
<div style="margin-left:1.5em;"><a href="/wiki/Madman_Entertainment" title="Madman Entertainment">Madman Entertainment</a></div>
</div>
<div style="overflow:hidden; width:100%;">
<div style="width:1.5em; float:left;"><small><sup style="font-style:normal;"><a href="/wiki/Northern_America" title="Northern America">NA</a></sup></small></div>
<div style="margin-left:1.5em;"><a href="/wiki/Funimation" title="Funimation">Funimation</a></div>
</div>
<div style="overflow:hidden; width:100%;">
<div style="width:1.5em; float:left;"><small><sup style="font-style:normal;"><a href="/wiki/United_Kingdom" title="United Kingdom">UK</a></sup></small></div>
<div style="margin-left:1.5em;"><a href="/wiki/Manga_Entertainment" title="Manga Entertainment">Manga Entertainment</a></div>
</div>
</td>
</tr>
<tr>
<th scope="row">Network</th>
<td><a href="/wiki/Tokyo_MX" title="Tokyo MX" class="mw-redirect">Tokyo MX</a>, <a href="/wiki/Mainichi_Broadcasting_System" title="Mainichi Broadcasting System">MBS</a>, <a href="/wiki/Nippon_BS_Broadcasting" title="Nippon BS Broadcasting">BS11</a>, <a href="/wiki/Television_Aichi_Broadcasting" title="Television Aichi Broadcasting">TVA</a></td>
</tr>
<tr>
<th scope="row">Original run</th>
<td><span class="nowrap">January 5, 2014</span> – <span class="nowrap">March 23, 2014</span></td>
</tr>
<tr>
<th scope="row">Episodes</th>
<td>12 <span class="noprint">(<a href="/wiki/List_of_Noragami_episodes#Season_1" title="List of Noragami episodes">List of episodes</a>)</span></td>
</tr>
<tr>
<td colspan="2" style="text-align:center;background:#CCF; font-weight:bold;"><a href="/wiki/Original_animation_DVD" title="Original animation DVD" class="mw-redirect">Original animation DVD</a></td>
</tr>
<tr>
<th scope="row">Directed&#160;by</th>
<td>Kotaro Tamura</td>
</tr>
<tr>
<th scope="row">Written&#160;by</th>
<td>Deko Akao</td>
</tr>
<tr>
<th scope="row">Music&#160;by</th>
<td><a href="/wiki/Taku_Iwasaki" title="Taku Iwasaki">Taku Iwasaki</a></td>
</tr>
<tr>
<th scope="row">Studio</th>
<td><a href="/wiki/Bones_(studio)" title="Bones (studio)">Bones</a></td>
</tr>
<tr>
<th scope="row">Released</th>
<td><span class="nowrap">February 17, 2014</span> – <span class="nowrap">July 17, 2014</span></td>
</tr>
<tr>
<th scope="row">Episodes</th>
<td>2</td>
</tr>
<tr>

1 个答案:

答案 0 :(得分:1)

不要在html上执行任何类型的字符串搜索。 Html具有嵌套结构,可以包含编码字符。正则表达式将失败或至少变得太复杂。不要将html视为XML。 Html可能包含不匹配的标签。

最好的方法是Html Agility Pack。它非常宽容,可以处理未封闭的标签和其他奇怪的东西。

相关问题