Advertisement
Guest User

Iowa Data Scraping

a guest
Aug 16th, 2015
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. import requests
  2. from bs4 import BeautifulSoup
  3.  
  4. def main():
  5.     url = "https://docs.google.com/spreadsheets/d/1TZKeP3gg8jC8gN9wducYUKNEuWd-ETUWIcfgsg9mqik/pubhtml/sheet?headers\x3dfalse&gid=1024335575"
  6.     r = requests.get(url)
  7.    
  8.     html = r.content
  9.     soup = BeautifulSoup(html, "html.parser")
  10.    
  11.     table = soup.find_all("td")
  12.  
  13.     dataList = list()
  14.     candidateList = list()
  15.     percentageList = list()
  16.  
  17.     for row in table:
  18.         if(row.text!=""):
  19.             dataList.append(row.text)
  20.  
  21.     for i in range(6, 24, 4):
  22.         candidateList.append(dataList[i])
  23.  
  24.     for i in range(8, 28, 4):
  25.         percentageList.append(dataList[i])
  26.  
  27.     for i in [3, 1, 2, 0, 4]:
  28.         print(candidateList[i] + ": " + percentageList[i])
  29.        
  30. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement