Skip to main content
pquery
======

grep for HTML; CLI for pyquery

## Demo

```
$curl -s https://github.com/hupili/pquery | pquery '.content a' -p text
.gitignore
LICENSE
MANIFEST.in
README.md
pquery
setup.py
```

`pquery` is intended to integrate into your UNIX pipeline.

## Install

`pip install pquery`

## Syntax

```
Usage:
pquery <selector>
pquery <selector> -p <projector>
pquery <selector> -f <format_string>
pquery -h | --help

Options:
-p: project the dict onto field `<projector>`.
-f: equivalent of `<format_string>.format(item)`,
where item is the dict form of one selected HTML element.
-h | -v: shows this doc.

Dict keys:
'tag': The HTML tag
'html': Inner HTML of the element
'text': Inner text of the element
...: [optional] Other attributes: e.g. 'href'
```

## Why

`grep` is powerful for **lines**.
HTML is structured and not line processor friendly.
CSS selector is a natural grep for HTML.
This script simply wraps [pyquery](http://pyquery.readthedocs.org/en/latest/) to provide a CLI.

## Example 1

A [course webpage](https://class.coursera.org/crypto-008/wiki/LectureSlidesPublicCourse)
lists slides in `pdf` and `pptx`.
Want to download all the PDFs.
This saves you some click.

```
wget --load-cookies=cookies.txt -O- 'https://class.coursera.org/crypto-008/wiki/LectureSlidesPublicCourse' | pquery a -p href | grep pdf | xargs -P 5 -I{} wget {}
```

It's tedious to directly grep the PDF links out from HTML.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pquery-1.1.tar.gz (2.9 kB view details)

Uploaded Source

File details

Details for the file pquery-1.1.tar.gz.

File metadata

  • Download URL: pquery-1.1.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pquery-1.1.tar.gz
Algorithm Hash digest
SHA256 1136160d6b70bdc76d43512f4ca4302def3f0829d5dea1f72f6221ce1c2ef204
MD5 64f3a40fe1e769abd6ab635cf15c30e8
BLAKE2b-256 0b80cf1e414569de5c489a961133da2412d3d698e8b47d05866132050ae29072

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page