HTMLAgilityPack 和
上的分离
我有一些 html,由
分隔,例如:
Jack Janson
<br/>
309 123 456
<br/>
My Special Street 43
检索 3 列信息的最简单方法是什么?
我不是 XPath 专家,因此另一种方法是在换行符上分隔字符串,然后仅使用数组。有更聪明的方法吗?
更新:忘记格式化代码。
I have some html, which is separated by <br/>
e.g.:
Jack Janson
<br/>
309 123 456
<br/>
My Special Street 43
What is the easiest way to retrieve the information in 3 columns?
I am not an XPath expert, so another approach would be to separate the string on the line break, and just work with the array. Is there a smarter way to do it?
Update: Forgot to format the code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在基于 XML 的纯 XPATH 中,您将使用如下 XPATH 表达式:
//preceding-sibling::br
或//following-sibling::br
(请参阅此处有关 XPATH 轴 的帮助)但是,您会发现 XPATH over HTML 实现Html Agility Pack 中不支持纯文本节点或 XPATH 选择表达式中的(属性节点)(
//br/text()
或//br/@blah
不支持例如工作)。请注意,它适用于过滤器,因此,这些//br[text()='blah']
或//br[@att='blah']
有效。因此,回到问题,您需要将 XPATH 和代码结合起来,如下所示:
这将输出
In pure XPATH over XML, you would use an XPATH expression like this:
//preceding-sibling::br
or//following-sibling::br
(see here for help on XPATH Axes)But, the XPATH over HTML implementation that you'll find in Html Agility Pack does not support pure text node or (Attribute node) in XPATH selection expressions (
//br/text()
or//br/@blah
do not work for example). Note it works in filters, so, these//br[text()='blah']
or//br[@att='blah']
work.So, back to the question, you need to combine XPATH and code, something like this:
That will output