xidel icon indicating copy to clipboard operation
xidel copied to clipboard

any more examples for xquery?

Open ralyodio opened this issue 3 years ago • 4 comments

I can't find much online. I'm trying to parse html and convert to json with some massaging.

ralyodio avatar Jan 29 '21 21:01 ralyodio

May I suggest you have a look at:

  • http://videlibri.sourceforge.net/xidel.html#docs
  • https://sourceforge.net/p/videlibri/code/ci/tip/tree/programs/internet/xidel/examples/
  • Xidel's mailing list
  • https://stackoverflow.com/questions/tagged/xidel
  • https://stackoverflow.com/search?q=xidel
  • https://github.com/Reino17/xivid/blob/master/xivid_notes.txt

The last url is me. Comments are in Dutch, but maybe you'll find them useful nonetheless.

P.s. Since you already know Stack Overflow, a response would help.

Reino17 avatar Jan 29 '21 22:01 Reino17

For some reason I'm not getting the <ticker> tag in the output, just the raw values. Am I misunderstanding how this should work?

#!/usr/bin/env sh

xidel -s https://www.marketbeat.com/short-interest/ --xquery '
for $row in //tbody/tr
	let $ticker := $row//td[1]//div[@class="ticker-area"]
	return <ticker>{$ticker}</ticker>
'


ralyodio avatar Feb 07 '21 21:02 ralyodio

You're probably looking for:

xidel -s https://www.marketbeat.com/short-interest --xquery '
  for $ticker in //tbody/tr/td[1]//div[@class="ticker-area"]/text() return
  <ticker>{$ticker}</ticker>
' --output-format=xml

Or perhaps:

xidel -s https://www.marketbeat.com/short-interest --xquery '
  serialize(
    <xml>{
      for $ticker in //tbody/tr/td[1]//div[@class="ticker-area"]/text() return
      <ticker>{$ticker}</ticker>
    }</xml>,
    {"indent":true(),"omit-xml-declaration":false()}
  )
'

Reino17 avatar Feb 08 '21 00:02 Reino17

ahh ok, that works.

ralyodio avatar Feb 08 '21 00:02 ralyodio