Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
/tqPublic

Perform a lookup by CSS selector on an HTML input

License

NotificationsYou must be signed in to change notification settings

plainas/tq

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tq is command line utility that performs an HTML element selection on HTML content passed to the stdin. Using css selectors that everybody knows.

Since input comes from stdin and output is sent to stdout, it can easily be used inside traditional UNIX pipelines to extract content from webpages and html files.

tq provides extra formating options such as json-encoding or newlines squashing, so it can play nicely with everyones favourite command line tooling.

Installation

sudo pip3 install https://github.com/plainas/tq/zipball/stable

Example usage

Get headlines from hacker news

curl https://news.ycombinator.com/news | tq -tj ".title a"

Get the title of an html document stored in a file

cat mydocument.html | tq -t title

Get all the images from a webpage

curl -s 'http://example.com/' | tq  "img" -a src | wget -i -

Notice that tq doesn't provide a way to make http requests or read files. You can use your favorite HTTP client, or provide the html source from any source you want.

For a modern, user friendly http client, check httpie. Or you can just use curl, wget, netcat, etc.

Command options

  • SELECTORA css selector

  • -a ATTRIBUTE --attr=ATTRIBUTEOutputs only the contents of the html ATTRIBUTE.

  • -t, --textOutputs only the inner text of the selected elements.

  • -p, --parentSelect the parent elements instead.

  • -q, --squashSquash lines.

  • -s, --squash-spaceSquash spaces.

  • -j, --json-linesJSON encode each match.

  • -J, --jsonOutput as json array of strings.

  • -v, --versionPrints tq version


[8]ページ先頭

©2009-2025 Movatter.jp