gpt4 book ai didi

c# - 使用 C# 从 html tbody 中提取数据

转载 作者:行者123 更新时间:2023-11-30 16:32:15 25 4
gpt4 key购买 nike

我正在使用 c# Web.Client 下载 html 字符串。

返回的 html 的一个小例子是

 <tbody class='resultBody ' id='Tbody2'>
<tr id='Tr2' class='firstRow'>
<td class='cbrow tier_Gold' rowspan='4'>
<input type='checkbox' name='listingId' value='452' id='Checkbox2' />
</td>
<td class='resNum' rowspan='4'>
<div class='node'>
B</div>
</td>
<td class='datarow busName' id='Td2'>

</td>
<td rowspan='2' class='resLinks'>
</td>
<td class="hoops" rowspan='2'>
</td>
</tr>
<tr>
<td class="datarow">
<dl class="addrBlock">
<dd class="bizAddr">
123 ABC St</dd>
</dl>
</td>
</tr>
</tbody>
<tbody class='resultBody ' id='Tbody3'>
<tr id='Tr3' class='firstRow'>
<td class='cbrow tier_Gold' rowspan='4'>
<input type='checkbox' name='listingId' value='99' id='Checkbox3' />
</td>
<td class='resNum' rowspan='4'>
<div class='node'>
B</div>
</td>
<td class='datarow busName' id='Td3'>

</td>
<td rowspan='2' class='resLinks'>
</td>
<td class="hoops" rowspan='2'>
</td>
</tr>
<tr>
<td class="datarow">
<dl class="addrBlock">
<dd class="bizAddr">
1111 Some St</dd>
</dl>
</td>
</tr>
</tbody>

我对 html 的 2 个元素感兴趣,但我不知道获取它们的最佳方法。我从元素中获取值并从中获取内部 html 的最佳方式是什么

任何建议都会很棒!!!

最佳答案

  • 下载HTML Agility Pack (free)
  • 创建一个新的 HtmlDocument
  • 加载html
  • 使用 DOM 导航或 xpath 查询(SelectSingleNode 等)查找元素
  • 访问您想要的元素的 InerHtml

API 类似于 XmlDocument,但它适用于非 xhtml 的 html。

关于c# - 使用 C# 从 html tbody 中提取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4171023/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com