Reputation: 171
Idea is to build-up a filter which would return HTML rows containing filter input value.
I came up with this so far but it returns nothing:
#!/usr/bin/python
from bs4 import BeautifulSoup
import cgi
import re
import urllib
data = cgi.FieldStorage()
filter = data.getvalue('request')
tree = urllib.urlopen('myfile.html').read()
soup = BeautifulSoup(tree)
tables = soup.findChildren('table')
mytable = tables[0]
rows = mytable.findAll('tr')
userrows = [t for t in rows if t.findAll(text=filter)]
text_file = open("tst.txt", "aw")
text_file.write(userrows)
text_file.close()
Tried with userrows = mytable.find('tr', text=filter)
but same outcome. Cmd says "expected a character buffer object"
What could be a possible issue here?
PC. I tried converting text=str(filter)
but same outcome
Upvotes: 0
Views: 206
Reputation: 12168
there a five kind of filter that beautifulsoup sport:
make sure your filter is one of those.
Upvotes: 1