I'd like also to know if there are tutorials for unexperienced users like I am, I couldn't find any, except for some examples here and there... For Xidel stuff, see https://github.com/benibela/xidel/issues/67#issuecomment-770084663. For XPath/XQuery stuff, see https://github.com/benibela/xidel/issues/106#issuecomment-1627386429. An extensive wiki is still on my to-do-list.
I'd like also to know if there are tutorials for unexperienced users like I am, I couldn't find any, except for some examples here and there... For Xidel stuff, see https://github.com/benibela/xidel/issues/67#issuecomment-770084663. For XPath/XQuery stuff, see https://github.com/benibela/xidel/issues/106#issuecomment-1627386429.
Hello Virgus, Have you actually removed (or commented) @ECHO OFF to debug your script? The first extraction... %XIDEL% -s %SRCURL% -e "//a[@class='downloadLink']/@href" ...doesn't only extract the first "apk-release-url". It extracts... xidel -s "https://www.apkmirror.com/apk/teamviewer/teamviewer-host/"^ -e "count(//a[@class='downloadLink']/@href)" 50 ...of them. And because of the FOR-loop only the last one will be assigned to %DLHREF%. If you only want the first one, use -e "(//a[@class='downloadLink'])[1]/@href"....
Hello Michael, sort() is for individual items, like sort(//div[@class='d-flex flex-column flex-md-row my-5 flex-justify-center']//@datetime) for instance. This won't work for sorting nodes. You'll have to use the XQuery "Order By Clause" in a FLWOR expression: xidel -s "https://github.com/Hibbiki/chromium-win32/releases" -e "for $x in //section order by $x//@datetime descending return $x/join((.//@datetime,h2),x:cps(9))" xidel -s "https://github.com/Hibbiki/chromium-win32/releases" -e ^"^ for $x...
That's a creative way to assign the (prettified) extraction-query to a variable. The outer parenthesis ( ) aren't necessary btw. Alternatively you could of course insert the extraction-query directly (with the necessary escape-characters): FOR /F "delims=" %A IN (' xidel -s "%fil%" -e ^" vrs:^=//div[@class^='d-flex flex-column flex-md-row my-5 flex-justify-center']/join^( ^( ^(.//@datetime^)[1]^, normalize-space^(.//span[@class^='ml-1 wb-break-all']^)^, div[@class^='col-md-9']//h1 ^)^,x:cps^(9^)...
Reino, nice to meet you again ... Wish I could say "likewise", but with you being anonymous that's not so obvious to me. --extract "vrs:=($cls)//normalize-space(span[@class = 'ml-1 wb-break-all'])" That would be... --extract "vrs:=normalize-space($cls//span[@class='ml-1 wb-break-all'])" or... --extract "vrs:=$cls/normalize-space(.//span[@class='ml-1 wb-break-all'])" I'd forget about the use of external variables if I were you, because that's something very difficult to accomplish in cmd, if possible...
All these are arrays. Sequences. I get everything - syntax error, endless loop and a string of all entries - but no array of normalized entries. What exactly have you tried? And what is the end-result you're actually looking for?
No problem. One last thing I forgot to mention: substring-before(@id,'_link') is another option instead of extract(@onclick,'\"(.*)\"',1). Probably easier because there are no double-quotes to deal with.
Multiple things are going wrong here. The only way to correctly export xidel variables with --output-format=cmd in a for-loop is by using "delims=" instead of "tokens=*". See https://stackoverflow.com/a/61972422. https://sourceforge.net/p/xidel/discussion/help/thread/3797db1dc8/ could also be informative. Within a for-loop you shouldn't end a line with a ^. Escape-character-hell! It's not about escaping the \", it's about (.*) between the second pair of double-quotes. In a for-loop the following...
Could you share the input/source you're processing as well as the exact cmd command and the error-message?
You could use --extract-exclude: xidel -s "%fil%" --extract-exclude=x86,x64 ^ -e "x86:=//a[contains(text(), 'x86')]" ^ -e "x64:=//a[contains(text(), 'x64')]" ^ -e "x86.id:=$x86/extract(@onclick, '.\"(.*)\"', 1)" ^ -e "x86.txt:=$x86/normalize-space(text())" ^ -e "x64.id:=$x64/extract(@onclick, '.\"(.*)\"', 1)" ^ -e "x64.txt:=$x64/normalize-space(text())" ^ --output-format=cmd There is however no need for so many extraction-queries. One is enough: xidel -s "%fil%" -e "//a[contains(text(), 'x86')]/(x86.id:=extract(@onclick,...
XPath notation: ECHO {"bitrate":1603000} | xidel -se "$json/decimal(bitrate)" ECHO {"bitrate":1603000} | xidel -se "$json/integer(bitrate)" ECHO {"bitrate":1603000} | xidel -se "$json/int(bitrate)" ECHO {"bitrate":1603000} | xidel -se "$json/bitrate cast as decimal" ECHO {"bitrate":1603000} | xidel -se "$json/bitrate cast as integer" ECHO {"bitrate":1603000} | xidel -se "$json/bitrate cast as int" dot notation, what you're using: ECHO {"bitrate":1603000} | xidel -se "($json).bitrate cast as decimal"...
XPath notation: ECHO {"bitrate":1603000} | xidel -se "$json/decimal(bitrate)" ECHO {"bitrate":1603000} | xidel -se "$json/integer(bitrate)" ECHO {"bitrate":1603000} | xidel -se "$json/int(bitrate)" ECHO {"bitrate":1603000} | xidel -se "$json/bitrate cast as decimal" ECHO {"bitrate":1603000} | xidel -se "$json/bitrate cast as integer" ECHO {"bitrate":1603000} | xidel -se "$json/bitrate cast as int" dot notation, what you're using: ECHO {"bitrate":1603000} | xidel -se "($json).bitrate cast as decimal"...
Hello Michael, This is more of a cmd question than a question about xidel, but no matter. You're probably looking for -e "$json" 2>NUL.
I also get the same error message with the normal Windows binary, BUT not with the OpenSSL binary. How very peculiar! However... xidel t:\json --extract "($json)/version" With the input first, followed by the extraction query next (as it should), this works just fine. Btw, the parentheses are only needed when you use the dot-notation (-e "($json).version"). Otherwise -e "$json/version" will do just fine. And as of r7880 the stdin dash (-) isn't needed anymore, so ECHO {"version":1} | xidel -e "$json/version"...
That's great, but I think it's worth noting however that if you want to output valid xml, then you'd better do... xidel input.xml -se "//div/*" --output-format=xml --output-declaration="<?xml version=\"1.0\" encoding=\"utf-8\"?>" <?xml version="1.0" encoding="utf-8"?> <xml> <p>Hello</p> <span>World</span> </xml> On Win10 you could try without --output-declaration, but as my cmd's code-page defaults to 437 I'm getting <?xml version="1.0" encoding="ibm437"?>
In cmd you can't assign new lines (\r\n) to a variable. The first method only works for 1 single line output, so you'd have to string-join the text-nodes with xidel if you want "Hello World" as output: C:\>FOR /F "delims=" %A IN ('xidel input.xml -se "join(//div/*)"') DO SET my_var1=%A C:\>SET my_var1=Hello World But the tags are stripped. That's what xidel does. If you really want the tags preserved, you'd have to use outer-xml(): xidel input.xml -se "//div/*/outer-xml(.)" <p>Hello</p> <span>Wo...
Either directly... FOR /F "delims=" %A IN ('xidel "in.xml" -e "//my_node"') DO SET my_var=%A ...or let Xidel do it... FOR /F "delims=" %A IN ('xidel "in.xml" -e "my_var:=//my_node" --output-format^=cmd') DO %A %A is for the command-line. In a batch-file use %%A.
This discussion was already finished, so I suggest you start a new discussion, instead of hijacking this one.
That's good to hear! You're welcome.
There are different ways to accomplish this, but this is how I would do it. I'm going to assume 'input.csv': urltoparse,tokentoparse http://intranet/readingarea/pages/service/personalpages/D41952.aspx,dappl http://intranet/readingarea/pages/service/personalpages/D41959.aspx,dappl I'm also going to assume the urls with the tokens are inside a <img src="*.jpg"> node. To ignore the first line in 'input.csv' I'd create a sequence of every new line and select line #2 and onward: xidel -s input.csv -e...
Could you post an example of this text-file?
See http://videlibri.sourceforge.net/xidel.html#examples #13. I believe this query should work: $ xidel -s --xml b.xml -e 'transform(/,function($x){$x/(if (name()="e") then () else .)}) ' <?xml version="1.0" encoding="ibm437"?> <d/> <c> <d> </d> </c> <d/> <c> </c> <d/> encoding="ibm437"? My shell's code page is CP437. At the moment I don't know how I can have it put out encoding="utf-8"?. Benito would have to answer that.
See http://videlibri.sourceforge.net/xidel.html#examples #13. I believe this query should work: $ xidel -s --xml b.xml -e 'transform(/,function($x){$x/(if (name()="e") then remove($x,1) else .)}) ' <?xml version="1.0" encoding="ibm437"?> <d/> <c> <d> </d> </c> <d/> <c> </c> <d/> encoding="ibm437"? My shell's code page is CP437. At the moment I don't know how I can have it put out encoding="utf-8"?. Benito would have to answer that.
Seeing you're on Windows that's because using \" inside double quotes will get you into lots of trouble. Use single quotes: FOR /F "delims=" %%A IN ('xidel -s "page.html" -e "name:=json(substring-after (//script,'myvar ='))/name" -e "lastname:=json(substring-after(//script,'myva r ='))/lastname" --output-format^=cmd') DO %%A You can use 1 query to export both variables btw: FOR /F "delims=" %%A IN ('xidel -s "page.html" -e "json(substring-after(//scr ipt,'myvar ='))/(name:=name,lastname:=lastname)"...
Seeing you're on Windows that's because using \" inside double quotes will get you into lots of trouble. Use single quotes: FOR /F "delims=" %%A IN ('xidel -s "page.html" -e "name:=json(substring-after(//script,'myvar ='))/name" -e "lastname:=json(substring-after(//script,'myvar ='))/lastname" --output-format^=cmd') DO %%A You can use 1 query to export both variables btw: FOR /F "delims=" %%A IN ('xidel -s "page.html" -e "json(substring-after(//script,'myvar ='))/(name:=name,lastname:=lastname)"...
I don't normally use CSS expressions (Benito would have to answer that), but an XPath expression on Linux would be: xidel "https://www.fanfiction.net/s/10572453/57/Alias" -f '//span/button[starts-with(.,"Next")]/extract(@onClick,"'\''(.+)'\''",1)' -e '$url' **** Retrieving (GET): https://www.fanfiction.net/s/10572453/57/Alias **** **** Processing: https://www.fanfiction.net/s/10572453/57/Alias **** **** Retrieving (): https://www.fanfiction.net/s/10572453/58/Alias **** **** Processing: https://www.fanfiction.net/s/10572453/58/Alias...