View Single Post
Old May 22nd, 2006, 11:57 AM   #107
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
I'm not quite sure what you're asking. This code results in all the tables on the page:
soup.fetch("table")
And this code results in all the links in table 2:
soup.fetch("table")[2].fetch("a")
Similarly, this code gets all the "td" tags in table 2:
soup.fetch("table")[2].fetch("td")
It might help to give you a quick run-through of object syntax. Take this following code:
chair.colour
This code refers to the "colour" property of the "chair" object.
chair.chopup()
This code calls the "chopup" method that belongs to the chair object. Thus, you can think of "." as meaning "belongs to". The "colour" property belongs to the chair object, as too does the "chopup" method. In programming lingo, they are members of the chair object.

Lets go back to BeautifulSoup:
links = soup.fetch("tables")[3].fetch("a")
It may be more obvious what this does if I expand it out a little:
all_tables = soup.fetch("tables")
table3 = all_tables[3]
links_in_table3 = table3.fetch("a")
Arevos is offline   Reply With Quote