Skip to content

Instantly share code, notes, and snippets.

@staticor
Created August 19, 2013 06:04
Show Gist options
  • Select an option

  • Save staticor/6266107 to your computer and use it in GitHub Desktop.

Select an option

Save staticor/6266107 to your computer and use it in GitHub Desktop.
rom BeautifulSoup import BeautifulSoup
pageSource='''...omitted for brevity...'''
soup = BeautifulSoup(pageSource)
alltables = soup.findAll( "table", {"border":"2", "width":"100%"} )
results=[]
for table in alltables:
rows = table.findAll('tr')
lines=[]
for tr in rows:
cols = tr.findAll('td')
for td in cols:
text=td.renderContents().strip('\n')
lines.append(text)
text_table='\n'.join(lines)
if 'Website' in text_table:
results.append(text_table)
print "Number of tables found : " , len(results)
for result in results:
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment