Skip to content

Instantly share code, notes, and snippets.

@frewsxcv
Created November 28, 2012 05:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frewsxcv/4159173 to your computer and use it in GitHub Desktop.
Save frewsxcv/4159173 to your computer and use it in GitHub Desktop.
import lxml.html
def get_incidents():
incidents = []
url = "http://slonews.thetribunenews.com/police_log/slo_log.php"
tree = lxml.html.parse(url)
for inc in tree.xpath("//table[@class='report']"):
inc_keys = inc.xpath("tr/td[@class='c1']")
inc_keys = [key.text_content() for key in inc_keys]
inc_values = inc.xpath("tr/td[@class='c2']")
inc_values = [value.text_content() for value in inc_values]
incidents.append(dict(zip(inc_keys, inc_values)))
return incidents[1:]
print(get_incidents())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment