Few hours ago, I just wondered if there is a Python library which I can use jQuery’s selectors to do some tasks on HTML files. PyQuery came up in search results.

A quick example explains all:

from pyquery import PyQuery as pq

d = pq(url='http://makeyjl.blogspot.com')
for ele_post in d('div.post'):
  post = pq(ele_post)
  print post('h3.post-title a').text()
  print post('div.post-body').text()
  print

It prints out all post titles and contents in this blog’s first page. It’s quick and simple.