PyQuery – Bringing jQuery Syntax to Python
Wednesday, 09 November 2011
If BeautifulSoup has ever felt unwieldily or you’ve looked upon Ruby’s NokoGiri with envy then you may find this funky Python library interesting.
PyQuery brings jQuery selector syntax to Python. If you’re already familiar with jQuery selectors you’ll be right at home. Even if you don’t its easy enough to pick up.
Here’s a quick example:
from pyquery import PyQuery as pq
d = pq(url="http://www.straw-dogs.co.uk")
# d is now like the jQuery $
for post in d('div.post'):
p = pq(post)
print p('h2').text()
PyQuery is also available to install via “pip”.