1

I am trying extract 2nd class name from <span> tag.

Due xidel documentation is really poor. I can't understand how to use function filter() or contains() and match <span> tag with class name "userstatus" and extract 2nd class name.

I have this at the moment but I can't tell to XIDEL tool match span tag with class when one parameter contain word userstatus.

xidel -e http://intranet.website.com '//li[@class='status']/span[@class==match("userstatus").....

Thank you for any suggestions

<li class="status">
  <span class="userstatus offline strongfont2">
    blaa bllaa foo text
  </span>
</li>

<li class="status">
  <span class="userstatus online italicfont1">
    blaa bllaa foo text
  </span>
</li>`

I need extract class parameters of <span> tag.
I don't need text or HTML content of <span> tag.

Result look like this:

class="userstatus offline strongfont2"

class="userstatus online italicfont1"

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
obi2016
  • 13
  • 5
  • *I have this at the moment but its not good syntax* - What does this mean? – Ed Heal Jan 04 '16 at 08:55
  • @obi2016 If you still wonder why you didn't get any output with the `xidel` binary, it's because the `-e` option is in the wrong place. --> `xidel -e ''` – Reino Apr 07 '20 at 21:25

2 Answers2

1

If you want to find <span> elements where the class attribute value contains "userstatus" and then return the class, you can use the following XPath 1.0 expression :

//li[@class='status']/span[contains(@class, 'userstatus')]/@class

Since Xidel seems to support XPath 2.0, you can use the following expression to extract only the second CSS class from the above <span> elements :

for $span in //li[@class='status']/span[contains(@class, 'userstatus')] 
return tokenize($span, ' ')[2]

I've never used Xidel before, but the above XPath seems to work when tested in Xidel online tester. You can also see demo of the above XPath in xpathtester.com

har07
  • 88,338
  • 12
  • 84
  • 137
  • Yes! this is exactly what I want to extract. But xidel is not printing result. It's working fine in testing tool but not with XIDEL binary no output... :( But we are close to solution! – obi2016 Jan 04 '16 at 10:09
0

You could use jQuery.hasClass() for determining whether the HTML element has a particular class associated or not - hasClass Example

Goku
  • 104
  • 1
  • 8
  • sorry i am writting shell script. I need explain how to use XIDEL features filter(....) and contains[.....] extracted data will be processes and validated in shell-script later. I am looking for pure XIDEL solution. It;s possible but I dont know how to write query :( – obi2016 Jan 04 '16 at 09:05
  • Simplier how to extract this line when is parent
  • . But class parameters may dynamic . only 3 words are always there **"userstatus" online** or **offline**. That's all.
  • – obi2016 Jan 04 '16 at 09:08