Created
November 28, 2012 05:20
-
-
Save frewsxcv/4159173 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 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