C
C#2y ago
langehk

❔ Scrape with HtmlAgilityPack

Hi. I'm trying to get the values on line 5 and 14. I've tried to get the span by class. However the InnerText is just an empty string.
var desc = childNode.SelectSingleNode("(//span[contains(@class, 'ux-textspans')])");
var desc = childNode.SelectSingleNode("(//span[contains(@class, 'ux-textspans')])");
Other spans on the site has id's which makes it a lot easier, but I can't figure out how to retrieve the value, when multiple spans has the same class. In this case there is 11 "fields/properties" listed with the same class. And I would only need some of them.
<div class=\"ux-layout-section-evo__col\">
<div class=\"ux-labels-values__labels\">
<div class=\"ux-labels-values__labels-content\">
<div>
<span class=\"ux-textspans\">Condition</span>
</div>
</div>
</div>
<div class=\"ux-labels-values__values\">
<div class=\"ux-labels-values__values-content\">
<div>
<span class=\"ux-expandable-textual-display-block-inline\">
<span data-testid=\"text\">
<span class=\"ux-textspans\">New with tags: A brand-new, unused, and unworn item (including handmade items) in the original ... </span>
<div class=\"ux-layout-section-evo__col\">
<div class=\"ux-labels-values__labels\">
<div class=\"ux-labels-values__labels-content\">
<div>
<span class=\"ux-textspans\">Condition</span>
</div>
</div>
</div>
<div class=\"ux-labels-values__values\">
<div class=\"ux-labels-values__values-content\">
<div>
<span class=\"ux-expandable-textual-display-block-inline\">
<span data-testid=\"text\">
<span class=\"ux-textspans\">New with tags: A brand-new, unused, and unworn item (including handmade items) in the original ... </span>
4 Replies
langehk
langehkOP2y ago
If I do like this I get the prop value I need, however I would also need the line 14 field.
var desc = childNode.SelectSingleNode("./div/div/div/div/span[contains(@class, 'ux-textspans')]").InnerHtml;
var desc = childNode.SelectSingleNode("./div/div/div/div/span[contains(@class, 'ux-textspans')]").InnerHtml;
But there must be a better way than doing this 😄
JUK_Karol
JUK_Karol2y ago
Why u didnt use "query selecor' istead of "childNode.SelectSingleNode" if u want get text of this elem "var desc = childNode.SelectSingleNode("./div/div/div/div/span[contains(@class, 'ux-textspans')]").InnerHtml;" I recommend use query selector and change path to "//div/span[contains(@class, 'ux-textspans')]"
langehk
langehkOP2y ago
Will try that. Thanks!
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.

Did you find this page helpful?