[Tutor] weather scraping with Beautiful Soup

Michiel Overtoom motoom at xs4all.nl
Sat Jul 18 14:37:56 CEST 2009


Sander Sweers wrote:

> 2009/7/18 Che M <pine508 at hotmail.com>:
>> table = soup.find("table","dataTable tm10")  #find the table
>> tbody = table.find("tbody")                  #find the table's body
> 
> You can do this in one step.
> 
> tbody = soup.find('tbody')

Yeah, but what if the document contains multiple tables, and you want 
explicitely the one with the class 'dataTable tm10'?

In such a case it doesn't hurt to progressively narrow down on the 
wanted element.

It also makes the scrape code more robust against page changes. Someone 
could add an extra table to the start of the page to host a search box, 
for example.


More information about the Tutor mailing list