github.com/suntong/cascadia@v1.3.0/README.e.md (about)

     1  ---
     2  SingleSel1: echo '<input type="radio" name="Sex" value="F" />' | tee /tmp/cascadia.xml | cascadia -i -o -c 'input[name=Sex][value=F]'
     3  SingleSel2: cascadia -i /tmp/cascadia.xml -o -c 'input[name=Sex][value=F]'
     4  ---
     5  
     6  ## {{toc 5}}
     7  - [Download/install binaries](#downloadinstall-binaries)
     8    - [The binary executables](#the-binary-executables)
     9    - [Distro package](#distro-package)
    10    - [Debian package](#debian-package)
    11  - [Install Source](#install-source)
    12  - [Author](#author)
    13  - [Contributors](#contributors-)
    14  
    15  ## {{.Name}} - CSS selector CLI tool
    16  
    17  The [Go Cascadia package](https://github.com/andybalholm/cascadia) implements CSS selectors for html. This is the command line tool, started as a thin wrapper around that package, but growing into a better tool to test CSS selectors without writing Go code:
    18  
    19  ## Usage
    20  
    21  ### $ {{exec "cascadia" | color "sh"}}
    22  
    23  Its output has two modes, _none-block selection mode_ and _block selection mode_, depending on whether the `--piece` parameter is given on the command line or not.
    24  
    25  For details about the concept of block and pieces, check out [andrew-d/goscrape](https://github.com/andrew-d/goscrape) (in fact, `cascadia` was initially developed just for it, so that I don't need to tweak Go code, build & run it just to test out the block and pieces selectors). Here is the exception:
    26  
    27  - Inside each page, there's 1 or more *blocks* - some logical method of splitting up a page into subcomponents.
    28  - Inside each block, you define some number of *pieces* of data that you wish
    29    to extract.  Each piece consists of a name, a selector, and what data to
    30    extract from the current block.
    31  
    32  This all sounds rather complicated, but in practice it's quite simple. See the next section for details.
    33  
    34  In summary,
    35  
    36  - The none-block selection mode will output the selection as HTML source by default
    37    * but if `-t`, or `--text` cli option is provided, the none-block selection mode will [output as text](https://github.com/suntong/cascadia/issues/6#issuecomment-980757881) instead.
    38      - By default, such text output will get their leading and trailing white space trimmed.
    39      - However, if `-R`, or `--Raw` cli option is provided, no trimming will be done.
    40  - The block selection mode will output HTML as text in a `tsv`/`csv` table form by default
    41    * if the `--piece` selection is prefixed with `RAW:`, then that specific block selection will output in HTML instead. See the following for details.
    42  
    43  ### Examples
    44  
    45  All the three `-i -o -c` options are required. By default it reads from `stdin` and output to `stdout`:
    46  
    47  ```sh
    48  $ {{shell .SingleSel1}}
    49  ```
    50  
    51  Either the input or the output can be followed by a file name:
    52  
    53  
    54  ```sh
    55  $ {{shell .SingleSel2}}
    56  ```
    57  
    58  
    59  ```sh
    60  $ cascadia -i /tmp/cascadia.xml -c 'input[name=Sex][value=F]' -o /tmp/out.html
    61  1 elements for 'input[name=Sex][value=F]':
    62  
    63  $ cat /tmp/out.html
    64  <input type="radio" name="Sex" value="F"/>
    65  ```
    66  
    67  More other options can be applied too:
    68  
    69  ```sh
    70  # using --wrap-html
    71  $ cascadia -i /tmp/cascadia.xml -c 'input[name=Sex][value=F]' -o /tmp/out.html -w
    72  1 elements for 'input[name=Sex][value=F]':
    73  
    74  $ cat /tmp/out.html
    75  <!DOCTYPE html>
    76  <html>
    77  <head>
    78  <meta charset="utf-8">
    79  <base href="">
    80  
    81  </head>
    82  <body>
    83  <input type="radio" name="Sex" value="F"/>
    84  </body>
    85  
    86  # using --wrap-html with --style
    87  $ cascadia -i /tmp/cascadia.xml -c 'input[name=Sex][value=F]' -o /tmp/out.html -w -y '<link rel="stylesheet" href="styles.css">'
    88  1 elements for 'input[name=Sex][value=F]':
    89  
    90  $ cat /tmp/out.html
    91  <!DOCTYPE html>
    92  <html>
    93  <head>
    94  <meta charset="utf-8">
    95  <base href="">
    96  <link rel="stylesheet" href="styles.css">
    97  </head>
    98  <body>
    99  <input type="radio" name="Sex" value="F"/>
   100  </body>
   101  ```
   102  
   103  - For more on using the `--style` option, check out ["adding styles"](https://github.com/suntong/cascadia/wiki/Adding-styles).
   104  - For more examples, check out the [wiki](https://github.com/suntong/cascadia/wiki/), which includes but not limits to, 
   105  
   106    * [None-block selection mode](https://github.com/suntong/cascadia/wiki#none-block-selection-mode)
   107      * [Multi-selection](https://github.com/suntong/cascadia/wiki#multi-selection)
   108    * [Block selection mode](https://github.com/suntong/cascadia/wiki#block-selection-mode)
   109      * [Block selection mode HTML output](https://github.com/suntong/cascadia/wiki#block-selection-mode-html-output)
   110      * [Block selection mode table output](https://github.com/suntong/cascadia/wiki#block-selection-mode-table-output)
   111      * [Attribute selection](https://github.com/suntong/cascadia/wiki#attribute-selection)
   112      * [Twitter Search](https://github.com/suntong/cascadia/wiki#twitter-search)
   113    * [Reconstruct the separated pages](https://github.com/suntong/cascadia/wiki#reconstruct-the-separated-pages)
   114    * [More On CSS Selector](https://github.com/suntong/cascadia/wiki#more-on-css-selector)
   115