Created
March 23, 2018 17:50
-
-
Save KameronKales/84a62ee049e6aff9a43c32122a537a4a to your computer and use it in GitHub Desktop.
Fixed code for Michael! Whoops
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
from bs4 import BeautifulSoup | |
import requests | |
import csv | |
from itertools import izip as zip | |
leads = [] | |
rates = [] | |
print "This is before the for loop has run" | |
print leads,rates | |
for i in range(5): | |
url = "https://www.greatschools.org/virginia/manassas/prince-william-county-public-schools/schools/?page={}".format(i) | |
r = requests.get(url, headers={'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36'}) | |
soup = BeautifulSoup(r.text, 'lxml') | |
print url | |
for sub_heading in soup.find_all("a", {"class":"open-sans_sb mbs font-size-medium rs-schoolName"}): | |
lead = sub_heading.text | |
leads.append(lead) | |
for sub_headings in soup.find_all("span", {"class":"gs-rating"}): | |
rate = sub_headings.text | |
rates.append(rate) | |
print "This is after the for loop has run" | |
print leads, rates | |
with open('some.csv', 'wb') as f: | |
writer = csv.writer(f) | |
writer.writerows(zip(leads, rates)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment