• Stars
    star
    105
  • Rank 328,196 (Top 7 %)
  • Language
    Python
  • License
    Other
  • Created over 13 years ago
  • Updated about 13 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A jQuery-like library for Python (fork of https://bitbucket.org/olauzanne/pyquery/)

PyQuery: a jQuery-like library for Python

PyQuery allows you to make jQuery-style CSS-selector queries on XML/HTML documents. The API is intended to match jQuery's API whenever possible, though it has been made more Pythonic where appropriate.

This project is a fork of the original PyQuery developed by Olivier Lauzanne in 2008; it is maintained by David Schoonover. Feedback and bug reports are both very welcome over on github.

Quickstart

You can use the PyQuery class to load an xml document from a string, a lxml document, from a file or from an url:

>>> from pyquery import PyQuery as pq
>>> from lxml import etree
>>> import urllib
>>> d = pq("<html></html>")
>>> d = pq(etree.fromstring("<html></html>"))
>>> d = pq(url='http://google.com/')
>>> # d = pq(url='http://google.com/', opener=lambda url: urllib.urlopen(url).read())
>>> d = pq(filename=path_to_html_file)

Now d is like the $ object in jQuery:

>>> d("#hello")
[<p#hello.hello>]
>>> p = d("#hello")
>>> print(p.html())
Hello world !
>>> p.html("you know <a href='http://python.org/'>Python</a> rocks")
[<p#hello.hello>]
>>> print(p.html())
you know <a href="http://python.org/">Python</a> rocks
>>> print(p.text())
you know Python rocks

You can use some of the pseudo classes that are available in jQuery but that are not standard in css such as :first, :last, :even, :odd, :eq, :lt, :gt, :checked, :selected, and :file.

>>> d('p:first')
[<p#hello.hello>]

Notes

  • PyQuery uses lxml for fast XML and HTML manipulation.
  • This is not a library to produce or interact with JavaScript code. If that's what you need, check out

More Repositories

1

bunch

A Bunch is a Python dictionary that provides attribute-style access (a la JavaScript objects).
Python
483
star
2

guess-language

Attempts to determine the natural language of a selection of Unicode (utf-8) text (a clone of http://code.google.com/p/guess-language with package metadata)
Python
47
star
3

connect-compiler

Development middleware to dynamically recompile derived files at serve-time.
JavaScript
41
star
4

colorbrewer-python

Colors from ColorBrewer for easy use in Python.
Python
28
star
5

Tab-Manager

The source code of the google chrome extension "Tab Manager"
JavaScript
27
star
6

coffeecup

CoffeeScript WSGI Middleware
Python
22
star
7

jsongrep

A shell tool to search and select bits out of a JSON document.
Python
15
star
8

shpaml

HAML-like HTML generator for python.
Python
14
star
9

node-remove

Sync and async rm -r for node.
JavaScript
11
star
10

coco-tmbundle

TextMate bundle for the Coco language
9
star
11

bitstring.js

Read and write packed binary strings, bit-by-bit, in JavaScript
JavaScript
9
star
12

nesting

Operator to construct nested rollups from lists of records
Python
8
star
13

underscore.nested

Nested and delegating object-graph extensions for Underscore.js
JavaScript
8
star
14

trowl

A Python web-scraper framework.
Python
6
star
15

operator.js

Functional operators for JavaScript, usable in both the browser and the server.
JavaScript
6
star
16

timeseries.js

Utilities for working with a collection of data columns aligned along a common timeline
JavaScript
5
star
17

u.js

A minimalist, functional utility library designed for embedding.
JavaScript
5
star
18

flashcookies

A shell tool to manipualte Flash cookies (.sol Flash SharedObject files)
Python
5
star
19

gamebook

It's a game book!
4
star
20

path.py

Mirror of Jason Orendorff's path.py. Sadly, the PyPi link points at http://www.jorendorff.com/articles/python/path/, which has been unavailable for some time.
4
star
21

py-lessly

A collection of random python tools.
Python
3
star
22

node-buildtools

Utilities for use in Jake/Cake/Coke build files
JavaScript
2
star
23

likepython

totally like omg python (bai)
2
star
24

kraken-old

Wikimedia analytics data services platform
Python
2
star
25

limn-mediawiki-ext

Embed Limn visualizations in Mediawiki
JavaScript
2
star
26

dsc.github.com

dsc.github.com
1
star
27

connect-compiler-extras

Extra compilers for connect-compiler
JavaScript
1
star
28

griddle

A browser-based grid tool for games.
1
star
29

flashme

Flashing Rose.
JavaScript
1
star
30

y-js

A functional javascript library for core type extension.
JavaScript
1
star
31

node-knockout

npm module for Knockout for use in Node (tests, etc)
JavaScript
1
star
32

fabric-tmbundle

TextMate bundle for Fabric
1
star
33

cue.js

A sensible async flow-control library.
1
star
34

hp-mor

HP:MoR Character Dialogue Counts
Python
1
star
35

scm-scripts

Useful scripts when working with source control.
1
star