I'm parsing some tables w/ BeautifulSoup, and came across an easy way to pick out the table's td
and th
tags. Try as I might, though, I don't know why this particular bit of code works (specifically: the very last line).
response = urlopen(url)
table = SoupStrainer('table',{'border': 0, 'cellpadding': 5})
soup = BeautifulSoup(html, parseOnlyThese = table)
soup.findAll(lamba tag: tag.name == "td")
What's the point of defining the anonymous function, dat
? I've tried soup.findAll(name == "td")
which doesn't work, but soup.findAll(lambda grop: grop.name == "td")
works. How is this lambda function interacting with BeautifulSoup and why do I need it? Is there another way of writing the same code that makes things a bit more clear?