XIDEL(1)
β¨ XIDEL β¨
okay bestie, welcome to Xidel β your new fave command line tool π (from the User Manuals section, no big deal, she's iconic π)
πΈ NAME πΈ
xidel β it's a command line tool to download and extract data from HTML/XML pages. literally that's her whole job and she ate π
π¦ SYNOPSIS π¦
the baby-steps trivial usage: extract an expression from a webpage, like this π
xidel http://www.example.org --extract //title
the next important option is --follow, which follows links on a page π«Ά so this example right here prints the titles of all the pages that are linked from http://www.example.org:
xidel http://www.example.org --follow //a --extract //title
β DESCRIPTION β
Xidel supports... a LOT. get comfy π
Extract expressions β there are a few different kinds of extract expressions:
- CSS 3 Selectors β for extracting simple elements β¨
- XPath 3 β for extracting values and calculating things with them π₯
- XQuery 3 β for creating new documents from the extracted values π
- JSONiq β for working with JSON apis
- Templates β for extracting several expressions in an easy way, using an annotated version of the page for pattern-matching π
- Multipage templates β i.e. a file that contains templates for several pages
- XPath 2 / XQuery 1 β for legacy queries (respect the elders π)
Following:
- HTTP Codes β redirections like 30x are automatically followed, while keeping things like cookies πͺ
- Links β it can follow all links on a page as well as some extracted values
Output formats:
- Adhoc β just prints the data in a human readable format
- XML β encodes the data in XML
- HTML β encodes the data in HTML
- JSON β encodes the data in a JSON
- bash/cmd β exports the data as shell variables π
Connections: HTTP / HTTPS as well as local files or stdin π«
Systems: Windows (using wininet), Linux (using synapse+openssl), Mac (with newest synapse) π
π OPTIONS π
- Call
xidel --helpto see a list of support command line options π - Call
xidel --usagefor a full reference π
π§ EXAMPLES - Basics π§
- Print all urls found by a google search.
xidel http://www.google.de/search?q=test --extract "//a/extract(@href, 'url[?]q=([^&]+)&', 1)[. != '']"
- Print the title of all pages found by a google search and download them:
xidel http://www.google.de/search?q=test --follow "//a/extract(@href, 'url[?]q=([^&]+)&', 1)[. != '']" --extract //title --download '{$host}/'
Generally follow all links on a page and print the titles of the linked pages:
- With XPath:
xidel http://example.org -f //a -e //title - With CSS:
xidel http://example.org -f "css('a')" --css title - With Templates:
xidel http://example.org -f "<a>{.}</a>*" -e "<title>{.}</title>"
- Another template example:
If you have an example.xml file like <x><foo>ood</foo><bar>IMPORTANT!</bar></x>, you can read the important part like:
xidel example.xml -e "<x><foo>ood</foo><bar>{.}</bar></x>"
(and this will also check, if the part with the ood is there, and fail otherwise π)
- Calculate something with XPath:
xidel -e "(1 + 2 + 3) * 1000000000000 + 4 + 5 + 6 + 7.000000008"
yes, the list jumps from 3 to 5, no I don't make the rules, I just report them π
- Print all newest stackoverflow questions with title and url:
xidel http://stackoverflow.com -e "<A class='question-hyperlink'>{title:=text(), url:=@href}</A>*"
- Print all reddit comments of an user, with html and url:
xidel "http://www.reddit.com/user/username/" --extract "<t:loop><div class='usertext-body'><div>{outer-xml(.)}</div></div><ul class='flat-list buttons'><a><t:s>link:=@href</t:s>permalink</a></ul></div></div></t:loop>" --follow "<a rel='nofollow next'>{.}</a>?"
- Check if your reddit letter is red:
Webscraping, combining CSS, XPath, JSONiq and automatically form evaluation:
xidel http://reddit.com -f "form(css('form.login-form')[1], {'user': '$your_username', 'passwd': '$your_password'})" -e "css('#mail')/@title"
Using the Reddit API:
xidel -d "user=$your_username&passwd=$your_password&api_type=json" https://ssl.reddit.com/api/login --method GET 'http://www.reddit.com/api/me.json' -e '($json).data.has_mail'
- Use XQuery, to create a html table of odd and even numbers:
xidel --xquery '<table>{for $i in 1 to 1000 return <tr><td>{$i}</td><td>{if ($i mod 2 = 0) then "even" else "odd"}</td></tr>}</table>' --output-format xml
- Export variables to bash
eval "$(xidel http://site -e 'title:=//title' -e 'links:=//a/@href' --output-format bash)"
This sets the bash variable $title to the title of the page and $links becomes an array of all links there π«Ά
π ENVIRONMENT π
Use XIDEL_OPTIONS to set global command line options. that's the whole section, she's short and sweet π
π AUTHOR π
Benito van der Zander, <benito_NOSPAM_benibela.de>, http://www.benibela.de
Download link: http://sourceforge.net/projects/videlibri/files/Xidel/
You can test it online on http://www.videlibri.de/cgi-bin/xidelcgi or directly by sending a request to the cgi service like:
http://www.videlibri.de/cgi-bin/xidelcgi?data=<html><title>foobar</title></html>&extract=//title&raw=true
π SEE ALSO π
and that's the whole manual bestie, slay π this page is coming at you from Linux, dated JUNE 2016 β vintage, but like, in a main character way βπ
π¦ where this page comes from
- nixos 26.05: xidel-unstable 2022-11-01
- nixpkgs unstable: xidel-unstable 2022-11-01
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms