Linux command
nokogiri 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Parse HTML file
nokogiri [file.html]
Fetch and parse URL
nokogiri [https://example.com]
Parse with CSS selector
nokogiri [file.html] -e "[doc.css('h1').text]"
Parse XML
nokogiri [file.xml] --type xml
Drop into an IRB session
nokogiri [file.html]
Validate against a RelaxNG schema
nokogiri [file.xml] --rng [schema.rng]
说明
nokogiri is the command-line front-end for the Nokogiri Ruby gem, a fast HTML/XML parser backed by libxml2 and libxslt. The CLI parses a file, URL, or stdin into a Nokogiri::HTML::Document or Nokogiri::XML::Document (bound as doc) and either drops you into an IRB session or runs the Ruby snippet supplied with -e so you can query it with CSS selectors (doc.css) or XPath (doc.xpath).
参数
- -e _CODE_
- Execute Ruby _CODE_ against the parsed document (which is bound to doc).
- --type _TYPE_
- Document type: xml or html. Defaults to autodetection by content type / extension.
- -C _FILE_
- Load a custom Ruby initialization file. Default: ~/.nokogirirc.
- -E, --encoding _ENCODING_
- Read input using the named character encoding (e.g. UTF-8, ISO-8859-1).
- --rng _URI_OR_PATH_
- Validate the document against the given RelaxNG schema.
- -v, --version
- Show the Nokogiri version.
- -?, --help
- Display help.
FAQ
What is the nokogiri command used for?
nokogiri is the command-line front-end for the Nokogiri Ruby gem, a fast HTML/XML parser backed by libxml2 and libxslt. The CLI parses a file, URL, or stdin into a Nokogiri::HTML::Document or Nokogiri::XML::Document (bound as doc) and either drops you into an IRB session or runs the Ruby snippet supplied with -e so you can query it with CSS selectors (doc.css) or XPath (doc.xpath).
How do I run a basic nokogiri example?
Run `nokogiri [file.html]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -e _CODE_ do in nokogiri?
Execute Ruby _CODE_ against the parsed document (which is bound to doc).