hubcap html — Get the outer HTML of an element

When to use

Get the outer HTML of an element. Use text for just the text content. Use source for the full page HTML.

Usage

hubcap html <selector>

Arguments

ArgumentTypeRequiredDescription
selectorstringyesCSS selector of the element to read

Flags

None.

Output

FieldTypeDescription
selectorstringThe selector that was used
htmlstringThe outer HTML of the element
{"selector":"#main","html":"<div id=\"main\"><p>Hello</p></div>"}

Errors

ConditionExit codeStderr
Element not found1error: element not found: <sel>
Chrome not connected2error: connecting to Chrome: ...
Timeout3error: timeout

Examples

Get the HTML of a container:

hubcap html '#main'

Get a nav element’s HTML and extract it with jq:

hubcap html 'nav' | jq -r '.html'

See also

  • text - Get inner text of an element
  • source - Get full page HTML source
  • query - Query a DOM element
  • attr - Get an attribute of an element