Created
August 20, 2013 15:08
-
-
Save prafulfillment/6282656 to your computer and use it in GitHub Desktop.
We're getting the stats from kickstarter projects.
This file contains 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
# coding: utf-8 | |
import requests | |
from bs4 import BeautifulSoup | |
from pprint import pprint as pp | |
from re import sub | |
def get_project(url): | |
r = requests.get(url) | |
kickstarter_html = r.text | |
soup = BeautifulSoup(kickstarter_html) | |
project_details = {} | |
project_details['name'] = soup.find(id="title").a.get_text() | |
project_details['num_backers'] = soup.find(id='backers_count')['data-backers-count'] | |
project_details['project_goal'] = soup.find(id='pledged')['data-goal'] | |
project_details['amount_pledged'] = soup.find(id='pledged')['data-pledged'] | |
project_details['amount_pledged_currency'] = soup.find(id='pledged').data['data-currency'] | |
funding_period = soup.find(id='meta').get_text().strip().split('\n') | |
project_details['funding_period'] = ' '.join(funding_period[2:4]) | |
project_details['funding_length'] = funding_period[-1][1:-1] | |
project_details['funding_length_num'] = int(funding_period[-1][1:-1].split(' ')[0]) | |
project_details['funding_length_unit'] = funding_period[-1][1:-1].split(' ')[1] | |
project_details['reward_counts'] = [(reward.h5.get_text(), | |
reward.find(True, {'class':'num-backers'}).get_text().strip()) | |
for reward in soup.findAll(True,{'class':'NS-projects-reward'})] | |
project_details['reward_counts_ints'] = [(int(sub(r'[^\d.]', '', reward.h5.get_text().split(' ')[1])), | |
int(reward.find(True, {'class':'num-backers'}).get_text().strip().split(' ')[0])) | |
for reward in soup.findAll(True,{'class':'NS-projects-reward'})] | |
print project_details['name'] | |
pp(project_details) | |
urls = [ | |
'http://www.kickstarter.com/projects/551975293/meta-the-most-advanced-augmented-reality-interface', | |
'http://www.kickstarter.com/projects/694835844/pool-tile-by-tile', | |
'http://www.kickstarter.com/projects/yonder/dino-pet-a-living-bioluminescent-night-light-pet', | |
'http://www.kickstarter.com/projects/2142509221/home-aquaponics-kit-self-cleaning-fish-tank-that-g?ref=most-funded', | |
] | |
for url in urls: | |
get_project(url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment