jquery-like HTML parsing in Python?

If you are fluent with BeautifulSoup, you could just add soupselect to your libs. Soupselect is a CSS selector extension for BeautifulSoup. Usage: from bs4 import BeautifulSoup as Soup from soupselect import select import urllib soup = Soup(urllib.urlopen(‘http://slashdot.org/’)) select(soup, ‘div.title h3’) [<h3><span><a href=”https://science.slashdot.org/”>Science</a>:</span></h3>, <h3><a href=”https://slashdot.org/articles/07/02/28/0120220.shtml”>Star Trek</h3>, ..]

Can you provide examples of parsing HTML?

Language: JavaScript Library: jQuery $.each($(‘a[href]’), function(){ console.debug(this.href); }); (using firebug console.debug for output…) And loading any html page: $.get(‘http://stackoverflow.com/’, function(page){ $(page).find(‘a[href]’).each(function(){ console.debug(this.href); }); }); Used another each function for this one, I think it’s cleaner when chaining methods.

HTML5: W3C vs WHATWG. Which gives the most authoritative spec?

Always choose WHATWG over W3C, no exceptions. Anne van Kesteren, (a WHATWG member who was a major contributor to the the HTML specification prior to the WHATWG and W3C versions diverging, and who remains a major contributor to the WHATWG specification) describes the current situation between WHATWG and W3C as follows on his blog: The … Read more

BeautifulSoup findAll() given multiple classes?

you can do this soup.findAll(True, {‘class’:[‘class1’, ‘class2’]}) example: >>> from bs4 import BeautifulSoup >>> soup = BeautifulSoup(‘<html><body><div class=”class1″></div><div class=”class2″></div><div class=”class3″></div></body></html>’) >>> soup.findAll(True, {“class”:[“class1”, “class2″]}) [<div class=”class1″></div>, <div class=”class2”></div>]