Using Xidel to scrape HTML:
for /f "usebackqDELIMS=" %a in (`^"xidel -s file.html -e 'json(//script[@type="application/ld+json"])/(string)()'^"`) do set "string=%a"
When running it in CMD output gives:
/(string)()'"`) was unexpected at this time.
I assume I need to escape some characters, following this documentation http://www.robvanderwoude.com/escapechars.php I tried lots of options, using carrots for various characters and backslash for [], but keep getting more errors.
Is there a certain one character that needs escaping or more or this isn't the case at all?
I see now I wrongfully assumed you were on Linux. In that case you have to fix the quoting. -e 'function("string")'
is for Linux, while -e "function('string')"
is for Windows.
Directly:
FOR /F "delims=" %A IN ('
xidel -s "file.html" -e "parse-json(//script[@type='application/ld+json'])/(string)()"
') DO SET "string=%A"
Or let Xidel generate the variable:
FOR /F "delims=" %A IN ('
xidel -s "file.html" -e "string:=parse-json(//script[@type='application/ld+json'])/(string)()" --output-format^=cmd
') DO %A
In a batch-file don't forget to escape the percent sign by adding another one (%%A
).