Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- os.chdir(r'C:\Users\<user>\Desktop')
- from bs4 import BeautifulSoup
- import requests
- import pandas as pd
- url = "https://www.akc.org/reg/dogreg_stats.cfm"
- r = requests.get(url)
- data = r.text
- soup = BeautifulSoup(data)
- table = soup.find_all('table')[0]
- rows = table.find_all('tr')[2:]
- data = {
- 'breeds' : [],
- 'rank2015' : [],
- 'rank2014' : [],
- 'rank2013' : []
- }
- for row in rows:
- cols = row.find_all('td')
- data['breeds'].append( cols[0].get_text().encode('utf-8').strip() )
- data['rank2015'].append( cols[1].get_text().encode('utf-8').strip() )
- data['rank2014'].append( cols[2].get_text().encode('utf-8').strip() )
- data['rank2013'].append( cols[3].get_text().encode('utf-8').strip() )
- dogData = pd.DataFrame( data )
- dogData.to_csv("AKC_Dog_Registrations.csv")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement