Created
February 26, 2015 19:09
-
-
Save ateoto/7037cb97344ed9e5e9f0 to your computer and use it in GitHub Desktop.
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
import requests | |
import csv | |
from bs4 import BeautifulSoup | |
rows = [] | |
for page_num in range(1, 11): | |
r = requests.get("http://www.sos.arkansas.gov/corps/search_corps.php?SEARCH=1&run={}&corp_name=%27".format(page_num)) | |
if r.status_code == requests.codes.ok: | |
res = r.content | |
soup = BeautifulSoup(res) | |
cells = soup.find_all("td", class_=lambda x: x and x == 'alt' or x and x == 'light') | |
for i in xrange(0, len(cells), 4): | |
rows.append([c.text.encode('utf-8') for c in cells[i].parent.findAll('td')]) | |
with open('output.csv', 'w') as csvfile: | |
csvwriter = csv.writer(csvfile) | |
for row in rows: | |
csvwriter.writerow(row) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment