Skip to content

Instantly share code, notes, and snippets.

@kbolt
Last active May 20, 2016 05:06
Show Gist options
  • Save kbolt/cb4a51e88880b170cfe06d12f95faf49 to your computer and use it in GitHub Desktop.
Save kbolt/cb4a51e88880b170cfe06d12f95faf49 to your computer and use it in GitHub Desktop.
#!python3
from bs4 import BeautifulSoup
import requests, json, pprint
r = requests.get('https://en.wikipedia.org/wiki/List_of_film_remakes_A-M')
soup = BeautifulSoup(r.content, 'html.parser')
table = soup.findAll('table')
tableContent = soup.select('#wikitable')
# Original version
tableData = [[cell.text for cell in row('td')[1:]]
for row in soup("tr")[1:5]]
# Nested Dictionary
data = {}
data['data'] = {}
for info in tableData:
title = info[0].split('(', 1)[0]
year = info[0].partition('(')[-1].rpartition(')')[0]
data['data'] = {'title':title, 'year': year}
pprint.pprint(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment