HTMLagilitypack xpath解析数据问题

编程入门 行业动态 更新时间:2024-10-15 14:15:49
本文介绍了HTMLagilitypack xpath解析数据问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试从网站上获取所有表格.然后遍历所有

I''m trying to get all the tables from a website. Then go through all the

<td></td>

节点. 由于某些原因,foreach循环从它经历的每个循环中获取相同的日期. HTML看起来像这样.

nodes. for some reason the foreach loop gets the same dates from every single loop it goes through. the HTML looks something like this.

<table> <tr> <td class=t>1.10</td><td class=t>2.10</td><td class=t>3.10</td><td class=t>4.10</td><td class=t>5.10</td><td class=t>6.10</td> </tr> </table>

HtmlNodeCollection weeks = doc.DocumentNode.SelectNodes("//table"); foreach(HtmlNode week in weeks) { HtmlNodeCollection tempdate = week.SelectNodes("//td[@class='t']"); for (int i = 0; i < 6; i++) { dates[i] = tempdate[i].InnerText; } }

推荐答案

您的逻辑看起来很简单. Your logic looks off. HtmlNodeCollection weeks = doc.DocumentNode.SelectNodes("//table"); foreach(HtmlNode week in weeks) { HtmlNodeCollection tempdate = week.SelectNodes("//td[@class=''t'']"); for (int i = 0; i < 6; i++) { dates[i] = tempdate[i].InnerText; } }

在您的代码中,您循环通过的每个内部循环只是在循环通过另一个HTMLNode(外部循环)时重置date []值. 您打算如何处理日期[]

In your code, every inner loop you loop through is just resetting the dates[] values when it loops through another HTMLNode (outer loop). What do you intend to do with dates[]

更多推荐

HTMLagilitypack xpath解析数据问题

本文发布于:2023-11-28 16:14:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1643083.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据   HTMLagilitypack   xpath

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!