Skip to content

Instantly share code, notes, and snippets.

@phillipsm
Last active August 29, 2015 14:23
Show Gist options
  • Save phillipsm/1f272a7caec08e44df2f to your computer and use it in GitHub Desktop.
Save phillipsm/1f272a7caec08e44df2f to your computer and use it in GitHub Desktop.
inmates = []
for inmate_link in inmates_links[:10]:
r = requests.get(inmate_link)
soup = BeautifulSoup(r.text)
inmate_details = {}
inmate_profile_rows = soup.select("#inmateProfile tr")
inmate_details['age'] = inmate_profile_rows[0].findAll('td')[0].text.strip()
inmate_details['race'] = inmate_profile_rows[3].findAll('td')[0].text.strip()
inmate_details['sex'] = inmate_profile_rows[4].findAll('td')[0].text.strip()
inmate_name_date_rows = soup.select("#inmateNameDate tr")
inmate_details['name'] = inmate_name_date_rows[1].findAll('td')[0].text.strip()
inmate_details['booked_at'] = inmate_name_date_rows[2].findAll('td')[0].text.strip()
inmate_address_container = soup.select("#inmateAddress")
inmate_details['city'] = inmate_address_container[0].text.split('\n')[2].strip()
inmates.append(inmate_details)
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment