Last active
May 20, 2016 05:06
-
-
Save kbolt/cb4a51e88880b170cfe06d12f95faf49 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!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