Skip to content

Instantly share code, notes, and snippets.

@ramuta
Created August 7, 2016 11:37
Show Gist options
  • Save ramuta/a3e4b413cce71797d9ba8b9babf498de to your computer and use it in GitHub Desktop.
Save ramuta/a3e4b413cce71797d9ba8b9babf498de to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
from urllib2 import urlopen
from BeautifulSoup import BeautifulSoup
url = "https://en.wikipedia.org/wiki/Game_of_Thrones"
response = urlopen(url).read()
soup = BeautifulSoup(response)
table_soup = soup.findAll("table", attrs={"class": "wikitable"})[1] # find the second table in the article
print table_soup
print("---------------------------")
print table_soup.caption.a.string
print("---------------------------")
print table_soup.table.tr.th
print("---------------------------")
print table_soup.findAll("th")
print("---------------------------")
print table_soup.findAll("th")[1].small.a.string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment