Replace more string literal searches with pyquery

Use pyquery to update the heading links.

Cache the parsed pyquery document and pass it into subsequent functions as an
optional argument, improving performance by avoiding re-parsing pages many
times.

Change-Id: I921cb6f196eb3b530968bc2417fae71d69d30282