yes | no |
Is there any way to get the contents of the table (yes ,no) besides beautifulsoup??
A python beginner,any help or any kind of direction will be of great help.
Thank you
解决方案
You can use the HTMLParser module that comes with the Python standard library.
>>> import HTMLParser
>>> data = '''
...
...
...
...
yes...
no...
...
...
... '''
>>> class TableParser(HTMLParser.HTMLParser):
... def __init__(self):
... HTMLParser.HTMLParser.__init__(self)
... self.in_td = False
...
... def handle_starttag(self, tag, attrs):
... if tag == 'td':
... self.in_td = True
...
... def handle_data(self, data):
... if self.in_td:
... print data
...
... def handle_endtag(self, tag):
... self.in_td = False
...
>>> p = TableParser()
>>> p.feed(data)
yes
no