【问题标题】:Search betwen htm tags c#在html标签之间搜索c#
【发布时间】:2015-12-23 22:05:44
【问题描述】:

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

喜欢第一行

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

足立时 得到这个 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>

【问题讨论】:

标签: c# html string tags


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-04
    • 1970-01-01
    • 2015-06-11
    • 1970-01-01
    • 2018-07-04
    • 2016-11-12
    • 2014-03-17
    • 2015-06-24
    相关资源
    最近更新 更多