如何在C#中使用x-path从HTML中提取span值? [英] How to extract span value from HTML using x-path in C#?
本文介绍了如何在C#中使用x-path从HTML中提取span值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I am stuck in a problem i just want to extract data from x-path attribute selector this is the div and span who's inner text want to show please help me out.
I am also performing this option in 16 times in a for each loop.
<div class="l">
<span id="ls_title_7596012" class="ls_h_desc" title="Required 10 marla old house in any block of bahria town">Required 10 marla old house in any block of bahria town</span>
</div>
I am also trying this but not succeed.
What I have tried:
var name = htmlDocument?.DocumentNode?.SelectNodes("//div[@class=\"1\"]//span[@class=\"ls_h_desc\"]//title")[0].InnerText;
推荐答案
显而易见的问题是,您显示的< div>
的类别为l
- 小写L
- 而您正在搜索1
的类。
你还试图选择一个名为title
的元素,它不存在;显示的标题是属性。
The obvious problem is that the<div>
you've shown has a class ofl
- a lower-caseL
- whereas you're searching for a class of1
.
You're also trying to select an element calledtitle
, which doesn't exist; the title shown is an attribute.
var name = htmlDocument?.DocumentNode?.SelectNodes("//div[@class=\"l\"]//span[@class=\"ls_h_desc\"]")[0].InnerText;
你试过jQuery吗?选择器?
i没有测试,但这样的事情应该有效
did you try jQuery selector?
i didn't test but something like this should work
(div.l> span.ls_h_desc)。val()
("div.l > span.ls_h_desc").val()
这篇关于如何在C#中使用x-path从HTML中提取span值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文