
import urllib.request
from pprint import pprint
from html_table_parser import HTMLTableParser


def url_get_contents(url):
    """ Opens a website and read its binary contents (HTTP Response Body) """
    req = urllib.request.Request(url=url)
    f = urllib.request.urlopen(req)
    return f.read()


def main():
    url = 'http://www.twitter.com'
    xhtml = url_get_contents(url).decode('utf-8')

    p = HTMLTableParser()
    p.feed(xhtml)
    pprint(p.tables)


if __name__ == '__main__':
    main()


import urllib.request
from pprint import pprint
from html_table_parser import HTMLTableParser


def url_get_contents(url):
    """ Opens a website and read its binary contents (HTTP Response Body) """
    req = urllib.request.Request(url=url)
    f = urllib.request.urlopen(req)
    return f.read()


def main():
    url = 'https://w3schools.com/html/html_tables.asp'
    xhtml = url_get_contents(url).decode('utf-8')

    p = HTMLTableParser()
    p.feed(xhtml)

    # Get all tables
    pprint(p.tables)

    # Get tables with id attribute
    pprint(p.named_tables)


if __name__ == '__main__':
    main()

Add named tables to the examples
Add named tables to the examples

  
  import urllib.request
  from pprint import pprint
  from html_table_parser import HTMLTableParser
  
  
  def url_get_contents(url):
      """ Opens a website and read its binary contents (HTTP Response Body) """
      req = urllib.request.Request(url=url)
      f = urllib.request.urlopen(req)
      return f.read()
  
  
  def main():
-     url = 'http://www.twitter.com'
+     url = 'https://w3schools.com/html/html_tables.asp'
      xhtml = url_get_contents(url).decode('utf-8')
  
      p = HTMLTableParser()
      p.feed(xhtml)
+ 
+     # Get all tables
      pprint(p.tables)
+ 
+     # Get tables with id attribute
+     pprint(p.named_tables)
  
  
  if __name__ == '__main__':
      main()
  
Add named tables to the examples
## Code Before:

import urllib.request
from pprint import pprint
from html_table_parser import HTMLTableParser


def url_get_contents(url):
    """ Opens a website and read its binary contents (HTTP Response Body) """
    req = urllib.request.Request(url=url)
    f = urllib.request.urlopen(req)
    return f.read()


def main():
    url = 'http://www.twitter.com'
    xhtml = url_get_contents(url).decode('utf-8')

    p = HTMLTableParser()
    p.feed(xhtml)
    pprint(p.tables)


if __name__ == '__main__':
    main()

## Instruction:
Add named tables to the examples
## Code After:

import urllib.request
from pprint import pprint
from html_table_parser import HTMLTableParser


def url_get_contents(url):
    """ Opens a website and read its binary contents (HTTP Response Body) """
    req = urllib.request.Request(url=url)
    f = urllib.request.urlopen(req)
    return f.read()


def main():
    url = 'https://w3schools.com/html/html_tables.asp'
    xhtml = url_get_contents(url).decode('utf-8')

    p = HTMLTableParser()
    p.feed(xhtml)

    # Get all tables
    pprint(p.tables)

    # Get tables with id attribute
    pprint(p.named_tables)


if __name__ == '__main__':
    main()
