Skip to content

Instantly share code, notes, and snippets.

@johananl
Last active November 5, 2020 22:44
Show Gist options
  • Save johananl/1dde5a2ce8465b845b51c33f076f95a4 to your computer and use it in GitHub Desktop.
Save johananl/1dde5a2ce8465b845b51c33f076f95a4 to your computer and use it in GitHub Desktop.
Michigan voter information search

Michigan voter information search

Installation

pip install beautifulsoup4
pip install requests

Usage

python voter-info.py <first_name> <last_name> <month_of_birth_int> <year_of_birth> <zip_code>

NOTE: month_of_birth_int is a number representing the month. For example, March is 3.

Example:

python voter-info.py William Bradley 3 1902 48207
{'Election date': '11/3/2020', 'Application received': '9/11/2020', 'Ballot sent': '9/19/2020', 'Ballot received': '10/2/2020'}
from bs4 import BeautifulSoup
import requests
import sys
url = 'https://mvic.sos.state.mi.us/Voter/SearchByName'
interesting = ['Election date', 'Application received', 'Ballot sent', 'Ballot received']
data = {
'FirstName': sys.argv[1],
'LastName': sys.argv[2],
'NameBirthMonth': sys.argv[3],
'NameBirthYear': sys.argv[4],
'ZipCode': sys.argv[5],
}
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
r = requests.post(url, data=data)
html = r.text
soup = BeautifulSoup(html, 'html.parser')
info = soup.find(id='lblAbsenteeVoterInformation')
if info is not None:
record = {}
for i in info:
if i.name == 'b' and i.contents[0] in interesting:
record[i.contents[0]] = i.next_sibling.next_sibling
print(record)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment