Last active
February 6, 2020 01:46
-
-
Save RussellSenior/daa4bf342b4f569afbf93cc39a19a4a5 to your computer and use it in GitHub Desktop.
Iowa Caucus results scraping script
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
curl https://results.thecaucuses.org/ | sed 's|<|\n<|g' | tail -n +540 | grep -v '</li>' | sed 's|<li>||' | sed 's|<div class="wrap">|COUNTY |' | awk '$1 ~ /COUNTY/ { county=$0 } $0 ~ /<ul>/ { pline = NR } NR == (pline + 1) { printf("%s\t%s",county,$0) } pline && NR > (pline + 1) && $0 !~ /<\/ul>/ { printf("\t%s",$0) } $0 ~ /<\/ul>/ { printf("\n") ; pline=0 }' | awk 'NF > 0' | sort |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment