My Twitter Bot: Keeping Up with Massachusetts Elections and Candidates

By Alessandra Ambrogio

http://elections.mytimetovote.com/dates/massachusetts.html (https://goo.gl/axTtaJ)

https://uselections.com/ma/ma.htm (https://goo.gl/LNguu7)

The goal of my Twitter Bot is to be able to check these two sites, one for any updates at all so people can check on election date information (new and old) and the latter for specific updates to that page in order to see changes to candidates and candidate information. Everyone deserves a resource, especially one resource that points to a myriad of resources instead of requiring people to remember large amounts of information.

Notes About Work Product based on Project 2 Rubric

I have conducted an analysis of the two target sites’ terms of service and robots.txt files and have determined that scraping is either explicitly allowed, not disallowed or otherwise permissible. The information is the type that is public domain, so if I did miss anything while conducting my analysis, the content I specificially scrape should be either explicitly allowed, not disallowed or otherwise permissible.

My Twitter Bot regularly parses multiple pieces of content, specifically information regarding whether one link's contents have changed at all and information about the date that the content of the other page was updated. Results are saved to a Google Sheet.

My Twitter Bot regularly produces tweets based on the interplay of changes in the content it parses.

Hopefully, I have provided enough information so that you can see the work that was done on this twitter bot. To note, I used a shortify think through Google to shorten the links that would tweet, a trick taught to me by a classmate (Matthew) who I am also grateful to for his help. I would be remiss if I did not thank Professor Colarusso for all of his help with fixing bugs and more, so thank you! Finally, welcome to my first Twitter Bot!

In [1]:
# Load the module for visiting and reading websites.
import urllib.request
# Load the module for running regular expressions (regex).
import re 
# Load the module for date and time stuff.
import datetime
# Define the variable now as equal to the current date and time.
now = datetime.datetime.now()
In [2]:
# Set the URLs you want to scrape.
url_1 = "http://elections.mytimetovote.com/dates/massachusetts.html"
url_2 = "https://uselections.com/ma/ma.htm"
In [3]:
import gspread
from oauth2client.service_account import ServiceAccountCredentials
scope = ['https://spreadsheets.google.com/feeds']

# Your spreadsheet's ID
document_key = "1pHSLeu4M5n03mHM1gPjzkZlMeMFRLoFoEbq5zYvmjFE"
# Your Google project's .json key
credentials = ServiceAccountCredentials.from_json_keyfile_name('../../../../../Twitter Bot P2-ce6234e6a3b1.json', scope)

# Use your credentials to authorize yourself.
gc = gspread.authorize(credentials)
# Open up the Sheet with the defined ID.
wks = gc.open_by_key(document_key)

worksheet = wks.worksheet("Sheet1")

worksheet.resize(worksheet.row_count)
In [4]:
import csv
csvfile = "output.csv"
list_of_lists = worksheet.get_all_values()
with open(csvfile, "w") as output:
    writer = csv.writer(output, lineterminator='\n')
    writer.writerows(list_of_lists)

import pandas as pd
output = pd.read_csv(csvfile)
output[:3]
Out[4]:
timestamp output_1 output_2
0 0 0 0
1 2017-10-23 12:07:32 b'<!DOCTYPE html>\n<html lang=\'en\'>\n<head>\... October 21, 2017
2 2017-10-23 12:30:09 b'<!DOCTYPE html>\n<html lang=\'en\'>\n<head>\... October 21, 2017
In [5]:
import twitter
from twitter import TwitterError

with open('../../../../../key.txt', 'r') as myfile:
    key=myfile.read()
    
with open('../../../../../secret.txt', 'r') as myfile:
    secret=myfile.read()
    
with open('../../../../../token_key.txt', 'r') as myfile:
    token_key=myfile.read()

with open('../../../../../token_secret.txt', 'r') as myfile:
    token_secret=myfile.read()

api = twitter.Api(consumer_key=key,
                  consumer_secret=secret,
                  access_token_key=token_key,
                  access_token_secret=token_secret)

Read the contents of your first webpage

When you run the next cell, your program will visit the first URL you defined above. It will then print out that page's HTML.

In [6]:
p_1 = urllib.request.build_opener(urllib.request.HTTPCookieProcessor).open(url_1).read()
print(p_1)
b'<!DOCTYPE html>\n<html lang=\'en\'>\n<head>\n<meta charset="utf-8">\n<meta name="viewport" content="width=device-width, initial-scale=1">\n<title>Massachusetts Elections Calendar - My Time To Vote</title>\n<meta name="description" content="Massachusetts Upcoming Election Dates and Deadlines.This include early Voting dates, voter registration dates, Absentee ballot voting and Poll Hours">\n<meta name="google-site-verification" content="bkrB4dLXoz3GNgAYBAiNWq0O6_H-zBH4kIVG2qCwSw4">\n\n<link rel=\'stylesheet\' href=\'http://www.mytimetovote.com/css/style.css\'>\n\n<link rel=\'stylesheet\' href=\'http://www.mytimetovote.com/css/ballot.css\'>\n<link rel="stylesheet" href="http://www.mytimetovote.com/css/bootstrap/bootstrap-3.3.6-dist/css/bootstrap.min.css">\n<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css">\n<link rel="shortcut icon" href="http://www.mytimetovote.com/css/images/mytimetovote.png" />\n\n<script src="http://www.mytimetovote.com/css/bootstrap/ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>\n<script src="http://www.mytimetovote.com/css/bootstrap/bootstrap-3.3.6-dist/js/bootstrap.min.js"></script>\n<script type="text/javascript" src="/js/jutils.js"></script>\n\n<script src="http://code.jquery.com/jquery-1.12.0.min.js"></script>\n<script src="http://code.jquery.com/jquery-migrate-1.3.0.min.js"></script>\n\n<script type="text/javascript" src="/js/newjquery.js"></script>\n<script type="text/javascript" src="http://www.mytimetovote.com/js/countdown.js"></script>\n<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>\n<script>\n  (adsbygoogle = window.adsbygoogle || []).push({\n    google_ad_client: "ca-pub-9916592529779417",\n    enable_page_level_ads: true\n  });\n</script>\n</head><body><div class=\'main-container\'>     <div class=\'col-xs-12 col-sm-12\' id=\'mttv-page-top\'>  <div class="col-xs-12 col-sm-12" id="headerNavNew"><nav id="mttv-top">\n                         <a href="http://www.mytimetovote.com/">Home</a>\n                         <a href="http://social.mytimetovote.com/">Login or Sign Up</a>\n                         <a href="http://www.mytimetovote.com/advertise.html">Advertise</a>\n                         <a href="http://www.mytimetovote.com/about.html">About</a> \n                         <a href="http://www.mytimetovote.com/jobs/">Jobs</a>\n                         <a href="http://mytimetovote.blogspot.com">Blog</a>\n                  <a href="https://www.facebook.com/mytime2vote/" target="_blank" title="Join us on Facebook"><img src="http://www.mytimetovote.com/images/logos/facebook.png" alt="facebook"/></a>\n                    <a href="https://twitter.com/mytime2vote" target="_blank" title="Follow us on twitter"><img src="http://www.mytimetovote.com/images/logos/twitter.png" alt="twitter"/></a> </nav></div><div class="col-xs-12 col-sm-12" id="headerLogoDiv" style="padding:0;margin:0;">\n                   <div class="headerTitleDiv" style="width:100%;">\n                               <div class="headerTitle">MyTimeToVote</div>\n                               <div class="smallHeaderTitle">MyTimeTo<br>Vote\n                                  <span class="smallDotCom">.com</span></div>\n                               <div class="subHeaderDiv">\n                                   <span class="subHeaderText">Promoting Democracy Through Education</span>\n                                    <span class="headerDotCom">.com</span>\n                               </div>\n                  </div>\n            </div> <div class="col-xs-12 col-sm-12" style="padding:0;margin:0;"><div class="navbar navbar-static-top bs-docs-nav" role="banner" id="navList"> <div class="navbar-header">\n                            <button class="navbar-toggle collapsed" type="button" data-toggle="collapse" \n                                data-target="#bs-navbar" aria-controls="bs-navbar" aria-expanded="false">\n                                <span class="sr-only">Toggle navigation</span> \n                                <span class="icon-bar"></span> \n                                <span class="icon-bar"></span>\n                                <span class="icon-bar"></span>\n                           </button> \n                       </div>\n                       <nav id="bs-navbar" class="collapse navbar-collapse">\n                            <ul class="nav navbar-nav" ><li><a class="bg-primary"  href="http://www.mytimetovote.com/">Home</a></li><li><a class=\'bg-default\' href=\'http://elections.mytimetovote.com/dates/\'>Elections Calendar</a></li><li><a  class=\'bg-primary\' href=\'http://presidentials.mytimetovote.com/\'>Presidentials</a></li><li><a class=\'bg-default\' href=\'http://canivote.mytimetovote.com/\'>Voting Guides</a></li><li><a class=\'bg-primary\' href=\'http://polls.mytimetovote.com/\'>Local Election Offices</a></li><li ><a class=\'bg-default\' href=\'http://elections.mytimetovote.com/elected_officials/\'>\n                     Your Elected Officials</a></li><li><a class="bg-primary"  href="http://feeds.mytimetovote.com/">News Feeds</a></li><li><a class="bg-default"  href="http://ballot.mytimetovote.com/">Ballot</a></li></ul></nav></div></div><div class=\'col-xs-12\' style=\'background:#333;text-align:center;margin:0;padding:0;\n                               padding-bottom:0.1em;\'>\n<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>\n<!-- responsive_adunit -->\n<ins class="adsbygoogle"\n     style="display:block"\n     data-ad-client="ca-pub-9916592529779417"\n     data-ad-slot="5996536534"\n     data-ad-format="auto"></ins>\n<script>\n(adsbygoogle = window.adsbygoogle || []).push({});\n</script>\n</div>\n\n    </div>    <div class=\'col-sm-12\' id=\'mttv-page-content\'>          <div class=\'col-xs-12\'>\n                             <table class=\'table\'>\n                                   <tr><td><h1>Massachusetts Elections Calendar</h1></td>\n                                       <td style=\'text-align:center;\'>\n                                       <h3>View Election Dates & Deadlines By state:</h3> <select class="form-control inline-select" name=\'stateid\' id=\'stateid\' onchange="openStatePage(\'http://elections.mytimetovote.com/dates\',this);"><option value=\'\'>All States</option><option value=\'AK\'>Alaska</option><option value=\'AL\'>Alabama</option><option value=\'AR\'>Arkansas</option><option value=\'AS\'>American_Samoa</option><option value=\'AZ\'>Arizona</option><option value=\'CA\'>California</option><option value=\'CO\'>Colorado</option><option value=\'CT\'>Connecticut</option><option value=\'DC\'>Washington_DC</option><option value=\'DE\'>Delaware</option><option value=\'FL\'>Florida</option><option value=\'GA\'>Georgia</option><option value=\'GU\'>Guam</option><option value=\'HI\'>Hawaii</option><option value=\'IA\'>Iowa</option><option value=\'ID\'>Idaho</option><option value=\'IL\'>Illinois</option><option value=\'IN\'>Indiana</option><option value=\'KS\'>Kansas</option><option value=\'KY\'>Kentucky</option><option value=\'LA\'>Louisiana</option><option value=\'MA\' selected=\'selected\'>Massachusetts</option><option value=\'MD\'>Maryland</option><option value=\'ME\'>Maine</option><option value=\'MH\'>Marshall_Islands</option><option value=\'MI\'>Michigan</option><option value=\'MN\'>Minnesota</option><option value=\'MO\'>Missouri</option><option value=\'MP\'>Northern_Marianas</option><option value=\'MS\'>Mississippi</option><option value=\'MT\'>Montana</option><option value=\'NC\'>North_Carolina</option><option value=\'ND\'>North_Dakota</option><option value=\'NE\'>Nebraska</option><option value=\'NH\'>New_Hampshire</option><option value=\'NJ\'>New_Jersey</option><option value=\'NM\'>New_Mexico</option><option value=\'NV\'>Nevada</option><option value=\'NY\'>New_York</option><option value=\'OH\'>Ohio</option><option value=\'OK\'>Oklahoma</option><option value=\'OR\'>Oregon</option><option value=\'PA\'>Pennsylvania</option><option value=\'PR\'>Puerto_Rico</option><option value=\'RI\'>Rhode_Island</option><option value=\'SC\'>South_Carolina</option><option value=\'SD\'>South_Dakota</option><option value=\'TN\'>Tennessee</option><option value=\'TX\'>Texas</option><option value=\'UT\'>Utah</option><option value=\'VA\'>Virginia</option><option value=\'VI\'>Virgin_Islands</option><option value=\'VT\'>Vermont</option><option value=\'WA\'>Washington</option><option value=\'WI\'>Wisconsin</option><option value=\'WV\'>West_Virginia</option><option value=\'WY\'>Wyoming</option></select></td>\n                                   </tr></table>\n                        </div>           <div class=\'col-sm-12\'>                <div class=\'col-xs-12 col-sm-8 col-md-8\' style=\'border-right:solid 1px #777;\'>\n                                    <nav><a href=\'#2017\'>2017 Elections Schedule</a> | <a href=\'#2018\'>2018 Elections Schedule</a> | </nav><a id=\'2017\'></a><h3 class=\'electionArt\'>2017 Election Dates & Deadlines</h3><div><section id=\'2017.October.10-209-MA-ST-E-ST-PE\' class=\'election-header\'>  <h4>2017 October 10 State Primary -- <em>Date: October 10,2017</em></h4>\n               <table class=\'table\' style=\'border-bottom:solid 1px #800;text-align:left;\'><tr><th class=\'deadline-header\' colspan=\'2\'><em>Deadlines</em></th></tr><tr ><td class=\'cac\' style=\'white-space:nowrap;\'>September 8, 2017</td>\n                                <td class=\'cac\'><b>Candidates: Last day to withdraw before the Election:</b>Last day and hour for filing withdrawals of or objections to all nomination papers and certificates of nomination with the Secretary of the Commonwealth.</td></tr><tr ><td class=\'vrc\' style=\'white-space:nowrap;\'>September 20, 2017</td>\n                                <td class=\'vrc\'><b>Voter Registration Ends:</b>Last day to register voters for the state primary; registration hours 9:00 A.M. to 8:00 P.M.</td></tr></table>\n                            <nav><a href=\'http://ballot.mytimetovote.com/massachusetts.html\'>View this election ballot |</a> \n                            <a href=\'\'> Back to top</a></nav></section>\n\n<section id=\'2017.November.7-209-MA-CT-E-CT-GM\' class=\'election-header\'>  <h4>2017 November 7 CITY OF BOSTON GENERAL MUNICIPAL ELECTION -- <em>Date: November 7,2017</em></h4>\n               <table class=\'table\' style=\'border-bottom:solid 1px #800;text-align:left;\'><tr><th class=\'deadline-header\' colspan=\'2\'><em>Deadlines</em></th></tr><tr ><td class=\'vrc\' style=\'white-space:nowrap;\'>October 18, 2017</td>\n                                <td class=\'vrc\'><b>Voter Registration Ends:</b>Last hour and day for registration of voters for Municipal Election. </td></tr></table>\n                            <nav><a href=\'http://ballot.mytimetovote.com/massachusetts.html\'>View this election ballot |</a> \n                            <a href=\'\'> Back to top</a></nav></section>\n</div><a id=\'2018\'></a><h3 class=\'electionArt\'>2018 Election Dates & Deadlines</h3><div><section id=\'2018.November.6-209-MA-ST-E-ST-GE\' class=\'election-header\'>  <h4>2018 November 6 General Election -- <em>Date: November 6,2018</em></h4>\n               <table class=\'table\' style=\'border-bottom:solid 1px #800;text-align:left;\'><tr><th class=\'deadline-header\' ><em>Deadlines</em></th></tr></table>\n                            <nav><a href=\'http://ballot.mytimetovote.com/massachusetts.html\'>View this election ballot |</a> \n                            <a href=\'\'> Back to top</a></nav></section>\n</div>\n                                    <div class=\'col-xs-12\'><div id=\'site-update\'><div class=\'feedh\'>Have A Question?</div><div id=\'site-update-block\'><p>One of MyTime2Vote\'s top priorities is providing our citizens access to all of the latest State and Federal election information. \n</p><h4>We\'re currently updating the following pages</h4><ul><li>State Ballots for this year election cycle</li><li>State Voting Guide</li><li>Elections Calendar</li><li>States Summary</li></ul><p>\n We are working day and night to give you up-to-date information, but we need your help! \n For website bug reports, data issues/rss feeds submission, feedback,\n or general questions about Mytimetovote.com, please send an email to info@mytime2vote.com \n\n</p></div></div></div>\n                                              \n                          </div>\n               <div class=\'col-xs-12 col-sm-4 col-md-4\' id=\'mttv-right-col\'>\n                                  <div class=\'col-xs-12\'> <div class=\'electionArth\'>Mytimetovote App</div>\n    <table class=\'table\'>\n     <tr><td colspan="2">Track State by State election dates, absentee ballot voting deadlines, voter registration deadlines, early voting dates, and more.\n      </td></tr>\n     <tr><td><a href="https://itunes.apple.com/us/app/mytimetovote/id1119639094#">\n      <img src="http://www.talknvote.com/images/app-store-badge.png" class="img-responsive" alt="Download On the Itunes Store"/> </a></td><td>\n    <a href="https://play.google.com/store/apps/details?id=com.mytimetovote.mttvapp" >\n    <img src="http://www.talknvote.com/images/play-store-badge.png" class="img-responsive" alt="Get it On Google Play Store"/> </a></td>\n    </tr></table>\n   \n  \n </div>\n                                   <div class=\'col-xs-12\' style=\'background:#333;text-align:center;\'>\n<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>\n<!-- responsive_adunit -->\n<ins class="adsbygoogle"\n     style="display:block"\n     data-ad-client="ca-pub-9916592529779417"\n     data-ad-slot="5996536534"\n     data-ad-format="auto"></ins>\n<script>\n(adsbygoogle = window.adsbygoogle || []).push({});\n</script>\n</div>\n                   <div class=\'col-xs-12\' style=\'border:solid 1px #333;text-align:center;\'></div>\n                                   <div class=\'col-xs-12\'><h3>When Is The Next Primary Election?</h3><p>\n \n    Primary elections and Caucuses are one means by which a political party \n     nominates candidates for the next general election.\n \n</p><ul class=\'list-group\'><li class=\'list-group-item\'>\n                         <a href=\'http://www.mytimetovote.com/2017-Primary-Election-Dates.html\'>\n                         2017 Primary Elections </a></li><li class=\'list-group-item\'>\n                         <a href=\'http://www.mytimetovote.com/2018-Primary-Election-Dates.html\'>\n                         2018 Primary Elections </a></li><li class=\'list-group-item\'>\n                         <a href=\'http://www.mytimetovote.com/2019-Primary-Election-Dates.html\'>\n                         2019 Primary Elections </a></li><li class=\'list-group-item\'>\n                         <a href=\'http://www.mytimetovote.com/2020-Primary-Election-Dates.html\'>\n                         2020 Primary Elections </a></li></ul></div> <div class=\'col-xs-12\'><h3>Breaking News Updates & Latest News Headlines </h3>\n                    <p>View the latest news and headline for U.S.,your state ...  \n                         <a href=\'http://feeds.mytimetovote.com/massachusetts.html\'>Check Latest News and Videos</a>\n                   </p></div> <div class=\'col-xs-12\'><h3>Am I eligible To Vote?</h3>\n                    <p>Most States require citizens to be registered in order to vote. Make sure you \n                          understand the voter registration requirements of your State of residence.\n                         <a href=\'http://canivote.mytimetovote.com/massachusetts.html#voterReg\'>Check if you are eligible to vote</a>\n                   </p></div> <div class=\'col-xs-12\'><h3>How Do I Register To Vote?</h3>\n                         <p>Check what options you have to register to vote in your state. \n                         <a href=\'http://canivote.mytimetovote.com/massachusetts.html#howtoReg\'>Click here for more information</a>\n                   </p></div> <div class=\'col-xs-12\'><h3>Where  Do I Register To Vote?</h3>\n                         <p>Don\'t wait, locate where you can register to vote, \n                           where to update your voter registration, or check your voter\n                          registration status and more\n                         <a href=\'http://polls.mytimetovote.com/massachusetts.html\'>Click here for more information</a>\n                   </p></div><div class=\'col-xs-12\'><h3>Can I Register To Vote At The Polls On Election Day?</h3>\n              <p>\n               Do you know if your state if one of the States that allow voters\n               to register at the polls on Election day? \n               <a href=\'http://canivote.mytimetovote.com/massachusetts.html#sdr\'>Click here for more information</a>\n            </p></div><div class=\'col-xs-12\'><h3>If My Address Has Changed Do I Need To Re-register To Vote?</h3>\n                <p>\n                  When you register to vote, your voter registration is linked to your residential address. When registered voters move, they are supposed to update their registration records with election officials before voting\n                <a href=\'http://canivote.mytimetovote.com/massachusetts.html#addressChanged\'>>>Check if you need to re-register to vote</a></p>\n              </div><div class=\'col-xs-12\'><h3>What\'s On The Ballot this year?</h3>\n                   <p>Find the offices that are up for election and\n                      public questions that will be on your ballot in the next election\n                   <a href=\'http://ballot.mytimetovote.com/massachusetts.html\'>Click here to see what will be on the statewide and local ballots</a>\n                </p></div><div class=\'col-xs-12\'><h3>Who Are My Elected Officials?</h3>\n                      <p>\n                        Find contact information for federal, state, and local government officials\n                        <a href=\'http://elections.mytimetovote.com/elected_officials/massachusetts.html\'>Click here to locate your elected officials</a>\n                      </p>\n                   </div> <div class=\'col-xs-12\'><h3>STATE OFFICIALS TERMS, AUTHORITY,SALARY, AND QUALITICATIONS</h3>\n                    <p>Do you know who\'s elected and who\'s appointed in your state? Or who can run for office? ...\n                         <a href=\'http://www.mytimetovote.com/massachusetts.html\'>Check Quickfacts about your state and state officials</a>\n                   </p></div><div class=\'col-xs-12\'><h3>What Political Parties Are There In My State?</h3>\n                      <p>\n                        Find contact information of qualified Political Parties in your state\n                        <a href=\'http://www.mytimetovote.com/Political-Parties/massachusetts.html\'>Click here to browse</a>\n                      </p>\n                   </div>\n                                                  </div>\n\n                        </div>\n\n  <div class=\'col-xs-12\' style=\'border:solid 1px #333;text-align:center;\' ></div> <div class="col-xs-12 col-sm-12" id="footer-block" >      <div id=\'footer-copyright\'>USA Elections -- COPYRIGHT 2017 www.mytimetovote.com all rights reserved</div> </div>\n  \n<!-- Start of StatCounter Code -->\n                     <script type="text/javascript">\n                       var sc_project=4155800;\n                       var sc_invisible=1;\n                       var sc_partition=51;\n                       var sc_click_stat=1;\n                       var sc_security="a9c7396f";\n                      </script> \n                     <script src="http://www.statcounter.com/counter/counter.js" type="text/javascript">\n                     </script>\n                     <noscript><div class="statcounter">\n                          <a target="_blank" href="http://www.statcounter.com/free_web_stats.html" title="website statistics">\n                            <img alt="website statistics" src="http://c.statcounter.com/4155800/0/a9c7396f/1/" class="statcounter"/></a></div></noscript>\n<!-- Start of StatCounter Code\n End of StatCounter Code -->\n<script type="text/javascript">var _gaq = _gaq || [];_gaq.push([\'_setAccount\', \'UA-34813453-1\']);\n  _gaq.push([\'_setDomainName\', \'mytimetovote.com\']);\n  _gaq.push([\'_trackPageview\']);\n  (function() {\n    var ga = document.createElement(\'script\'); ga.type = \'text/javascript\'; ga.async = true;\n    ga.src = (\'https:\' == document.location.protocol ? \'https://\' : \'http://\') + \'stats.g.doubleclick.net/dc.js\';\n    var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(ga, s);\n  })();</script>\n      <script>\ndocument.write(\'<script src="//sharebutton.net/plugin/sharebutton.php?type=vertical&u=\' + encodeURIComponent(document.location.href) + \'"></scr\' + \'ipt>\');\n</script>\n    \n\n  </div>\n\n\n                </div></body></html>'

Parse the site's contents

Scan the above HTML for the content you are trying to extract. Cut and paste the HTML above into the TEST STRING box over at Regex 101 and craft a regex that captures your desired content.

Remember the parenthetical is the group you're pulling out. Once you have a working regex, plug it into the code below, and run the cell. If it worked, you'll see you scraped data as an output.

In [7]:
output_1 = p_1
print (output_1)
b'<!DOCTYPE html>\n<html lang=\'en\'>\n<head>\n<meta charset="utf-8">\n<meta name="viewport" content="width=device-width, initial-scale=1">\n<title>Massachusetts Elections Calendar - My Time To Vote</title>\n<meta name="description" content="Massachusetts Upcoming Election Dates and Deadlines.This include early Voting dates, voter registration dates, Absentee ballot voting and Poll Hours">\n<meta name="google-site-verification" content="bkrB4dLXoz3GNgAYBAiNWq0O6_H-zBH4kIVG2qCwSw4">\n\n<link rel=\'stylesheet\' href=\'http://www.mytimetovote.com/css/style.css\'>\n\n<link rel=\'stylesheet\' href=\'http://www.mytimetovote.com/css/ballot.css\'>\n<link rel="stylesheet" href="http://www.mytimetovote.com/css/bootstrap/bootstrap-3.3.6-dist/css/bootstrap.min.css">\n<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css">\n<link rel="shortcut icon" href="http://www.mytimetovote.com/css/images/mytimetovote.png" />\n\n<script src="http://www.mytimetovote.com/css/bootstrap/ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>\n<script src="http://www.mytimetovote.com/css/bootstrap/bootstrap-3.3.6-dist/js/bootstrap.min.js"></script>\n<script type="text/javascript" src="/js/jutils.js"></script>\n\n<script src="http://code.jquery.com/jquery-1.12.0.min.js"></script>\n<script src="http://code.jquery.com/jquery-migrate-1.3.0.min.js"></script>\n\n<script type="text/javascript" src="/js/newjquery.js"></script>\n<script type="text/javascript" src="http://www.mytimetovote.com/js/countdown.js"></script>\n<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>\n<script>\n  (adsbygoogle = window.adsbygoogle || []).push({\n    google_ad_client: "ca-pub-9916592529779417",\n    enable_page_level_ads: true\n  });\n</script>\n</head><body><div class=\'main-container\'>     <div class=\'col-xs-12 col-sm-12\' id=\'mttv-page-top\'>  <div class="col-xs-12 col-sm-12" id="headerNavNew"><nav id="mttv-top">\n                         <a href="http://www.mytimetovote.com/">Home</a>\n                         <a href="http://social.mytimetovote.com/">Login or Sign Up</a>\n                         <a href="http://www.mytimetovote.com/advertise.html">Advertise</a>\n                         <a href="http://www.mytimetovote.com/about.html">About</a> \n                         <a href="http://www.mytimetovote.com/jobs/">Jobs</a>\n                         <a href="http://mytimetovote.blogspot.com">Blog</a>\n                  <a href="https://www.facebook.com/mytime2vote/" target="_blank" title="Join us on Facebook"><img src="http://www.mytimetovote.com/images/logos/facebook.png" alt="facebook"/></a>\n                    <a href="https://twitter.com/mytime2vote" target="_blank" title="Follow us on twitter"><img src="http://www.mytimetovote.com/images/logos/twitter.png" alt="twitter"/></a> </nav></div><div class="col-xs-12 col-sm-12" id="headerLogoDiv" style="padding:0;margin:0;">\n                   <div class="headerTitleDiv" style="width:100%;">\n                               <div class="headerTitle">MyTimeToVote</div>\n                               <div class="smallHeaderTitle">MyTimeTo<br>Vote\n                                  <span class="smallDotCom">.com</span></div>\n                               <div class="subHeaderDiv">\n                                   <span class="subHeaderText">Promoting Democracy Through Education</span>\n                                    <span class="headerDotCom">.com</span>\n                               </div>\n                  </div>\n            </div> <div class="col-xs-12 col-sm-12" style="padding:0;margin:0;"><div class="navbar navbar-static-top bs-docs-nav" role="banner" id="navList"> <div class="navbar-header">\n                            <button class="navbar-toggle collapsed" type="button" data-toggle="collapse" \n                                data-target="#bs-navbar" aria-controls="bs-navbar" aria-expanded="false">\n                                <span class="sr-only">Toggle navigation</span> \n                                <span class="icon-bar"></span> \n                                <span class="icon-bar"></span>\n                                <span class="icon-bar"></span>\n                           </button> \n                       </div>\n                       <nav id="bs-navbar" class="collapse navbar-collapse">\n                            <ul class="nav navbar-nav" ><li><a class="bg-primary"  href="http://www.mytimetovote.com/">Home</a></li><li><a class=\'bg-default\' href=\'http://elections.mytimetovote.com/dates/\'>Elections Calendar</a></li><li><a  class=\'bg-primary\' href=\'http://presidentials.mytimetovote.com/\'>Presidentials</a></li><li><a class=\'bg-default\' href=\'http://canivote.mytimetovote.com/\'>Voting Guides</a></li><li><a class=\'bg-primary\' href=\'http://polls.mytimetovote.com/\'>Local Election Offices</a></li><li ><a class=\'bg-default\' href=\'http://elections.mytimetovote.com/elected_officials/\'>\n                     Your Elected Officials</a></li><li><a class="bg-primary"  href="http://feeds.mytimetovote.com/">News Feeds</a></li><li><a class="bg-default"  href="http://ballot.mytimetovote.com/">Ballot</a></li></ul></nav></div></div><div class=\'col-xs-12\' style=\'background:#333;text-align:center;margin:0;padding:0;\n                               padding-bottom:0.1em;\'>\n<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>\n<!-- responsive_adunit -->\n<ins class="adsbygoogle"\n     style="display:block"\n     data-ad-client="ca-pub-9916592529779417"\n     data-ad-slot="5996536534"\n     data-ad-format="auto"></ins>\n<script>\n(adsbygoogle = window.adsbygoogle || []).push({});\n</script>\n</div>\n\n    </div>    <div class=\'col-sm-12\' id=\'mttv-page-content\'>          <div class=\'col-xs-12\'>\n                             <table class=\'table\'>\n                                   <tr><td><h1>Massachusetts Elections Calendar</h1></td>\n                                       <td style=\'text-align:center;\'>\n                                       <h3>View Election Dates & Deadlines By state:</h3> <select class="form-control inline-select" name=\'stateid\' id=\'stateid\' onchange="openStatePage(\'http://elections.mytimetovote.com/dates\',this);"><option value=\'\'>All States</option><option value=\'AK\'>Alaska</option><option value=\'AL\'>Alabama</option><option value=\'AR\'>Arkansas</option><option value=\'AS\'>American_Samoa</option><option value=\'AZ\'>Arizona</option><option value=\'CA\'>California</option><option value=\'CO\'>Colorado</option><option value=\'CT\'>Connecticut</option><option value=\'DC\'>Washington_DC</option><option value=\'DE\'>Delaware</option><option value=\'FL\'>Florida</option><option value=\'GA\'>Georgia</option><option value=\'GU\'>Guam</option><option value=\'HI\'>Hawaii</option><option value=\'IA\'>Iowa</option><option value=\'ID\'>Idaho</option><option value=\'IL\'>Illinois</option><option value=\'IN\'>Indiana</option><option value=\'KS\'>Kansas</option><option value=\'KY\'>Kentucky</option><option value=\'LA\'>Louisiana</option><option value=\'MA\' selected=\'selected\'>Massachusetts</option><option value=\'MD\'>Maryland</option><option value=\'ME\'>Maine</option><option value=\'MH\'>Marshall_Islands</option><option value=\'MI\'>Michigan</option><option value=\'MN\'>Minnesota</option><option value=\'MO\'>Missouri</option><option value=\'MP\'>Northern_Marianas</option><option value=\'MS\'>Mississippi</option><option value=\'MT\'>Montana</option><option value=\'NC\'>North_Carolina</option><option value=\'ND\'>North_Dakota</option><option value=\'NE\'>Nebraska</option><option value=\'NH\'>New_Hampshire</option><option value=\'NJ\'>New_Jersey</option><option value=\'NM\'>New_Mexico</option><option value=\'NV\'>Nevada</option><option value=\'NY\'>New_York</option><option value=\'OH\'>Ohio</option><option value=\'OK\'>Oklahoma</option><option value=\'OR\'>Oregon</option><option value=\'PA\'>Pennsylvania</option><option value=\'PR\'>Puerto_Rico</option><option value=\'RI\'>Rhode_Island</option><option value=\'SC\'>South_Carolina</option><option value=\'SD\'>South_Dakota</option><option value=\'TN\'>Tennessee</option><option value=\'TX\'>Texas</option><option value=\'UT\'>Utah</option><option value=\'VA\'>Virginia</option><option value=\'VI\'>Virgin_Islands</option><option value=\'VT\'>Vermont</option><option value=\'WA\'>Washington</option><option value=\'WI\'>Wisconsin</option><option value=\'WV\'>West_Virginia</option><option value=\'WY\'>Wyoming</option></select></td>\n                                   </tr></table>\n                        </div>           <div class=\'col-sm-12\'>                <div class=\'col-xs-12 col-sm-8 col-md-8\' style=\'border-right:solid 1px #777;\'>\n                                    <nav><a href=\'#2017\'>2017 Elections Schedule</a> | <a href=\'#2018\'>2018 Elections Schedule</a> | </nav><a id=\'2017\'></a><h3 class=\'electionArt\'>2017 Election Dates & Deadlines</h3><div><section id=\'2017.October.10-209-MA-ST-E-ST-PE\' class=\'election-header\'>  <h4>2017 October 10 State Primary -- <em>Date: October 10,2017</em></h4>\n               <table class=\'table\' style=\'border-bottom:solid 1px #800;text-align:left;\'><tr><th class=\'deadline-header\' colspan=\'2\'><em>Deadlines</em></th></tr><tr ><td class=\'cac\' style=\'white-space:nowrap;\'>September 8, 2017</td>\n                                <td class=\'cac\'><b>Candidates: Last day to withdraw before the Election:</b>Last day and hour for filing withdrawals of or objections to all nomination papers and certificates of nomination with the Secretary of the Commonwealth.</td></tr><tr ><td class=\'vrc\' style=\'white-space:nowrap;\'>September 20, 2017</td>\n                                <td class=\'vrc\'><b>Voter Registration Ends:</b>Last day to register voters for the state primary; registration hours 9:00 A.M. to 8:00 P.M.</td></tr></table>\n                            <nav><a href=\'http://ballot.mytimetovote.com/massachusetts.html\'>View this election ballot |</a> \n                            <a href=\'\'> Back to top</a></nav></section>\n\n<section id=\'2017.November.7-209-MA-CT-E-CT-GM\' class=\'election-header\'>  <h4>2017 November 7 CITY OF BOSTON GENERAL MUNICIPAL ELECTION -- <em>Date: November 7,2017</em></h4>\n               <table class=\'table\' style=\'border-bottom:solid 1px #800;text-align:left;\'><tr><th class=\'deadline-header\' colspan=\'2\'><em>Deadlines</em></th></tr><tr ><td class=\'vrc\' style=\'white-space:nowrap;\'>October 18, 2017</td>\n                                <td class=\'vrc\'><b>Voter Registration Ends:</b>Last hour and day for registration of voters for Municipal Election. </td></tr></table>\n                            <nav><a href=\'http://ballot.mytimetovote.com/massachusetts.html\'>View this election ballot |</a> \n                            <a href=\'\'> Back to top</a></nav></section>\n</div><a id=\'2018\'></a><h3 class=\'electionArt\'>2018 Election Dates & Deadlines</h3><div><section id=\'2018.November.6-209-MA-ST-E-ST-GE\' class=\'election-header\'>  <h4>2018 November 6 General Election -- <em>Date: November 6,2018</em></h4>\n               <table class=\'table\' style=\'border-bottom:solid 1px #800;text-align:left;\'><tr><th class=\'deadline-header\' ><em>Deadlines</em></th></tr></table>\n                            <nav><a href=\'http://ballot.mytimetovote.com/massachusetts.html\'>View this election ballot |</a> \n                            <a href=\'\'> Back to top</a></nav></section>\n</div>\n                                    <div class=\'col-xs-12\'><div id=\'site-update\'><div class=\'feedh\'>Have A Question?</div><div id=\'site-update-block\'><p>One of MyTime2Vote\'s top priorities is providing our citizens access to all of the latest State and Federal election information. \n</p><h4>We\'re currently updating the following pages</h4><ul><li>State Ballots for this year election cycle</li><li>State Voting Guide</li><li>Elections Calendar</li><li>States Summary</li></ul><p>\n We are working day and night to give you up-to-date information, but we need your help! \n For website bug reports, data issues/rss feeds submission, feedback,\n or general questions about Mytimetovote.com, please send an email to info@mytime2vote.com \n\n</p></div></div></div>\n                                              \n                          </div>\n               <div class=\'col-xs-12 col-sm-4 col-md-4\' id=\'mttv-right-col\'>\n                                  <div class=\'col-xs-12\'> <div class=\'electionArth\'>Mytimetovote App</div>\n    <table class=\'table\'>\n     <tr><td colspan="2">Track State by State election dates, absentee ballot voting deadlines, voter registration deadlines, early voting dates, and more.\n      </td></tr>\n     <tr><td><a href="https://itunes.apple.com/us/app/mytimetovote/id1119639094#">\n      <img src="http://www.talknvote.com/images/app-store-badge.png" class="img-responsive" alt="Download On the Itunes Store"/> </a></td><td>\n    <a href="https://play.google.com/store/apps/details?id=com.mytimetovote.mttvapp" >\n    <img src="http://www.talknvote.com/images/play-store-badge.png" class="img-responsive" alt="Get it On Google Play Store"/> </a></td>\n    </tr></table>\n   \n  \n </div>\n                                   <div class=\'col-xs-12\' style=\'background:#333;text-align:center;\'>\n<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>\n<!-- responsive_adunit -->\n<ins class="adsbygoogle"\n     style="display:block"\n     data-ad-client="ca-pub-9916592529779417"\n     data-ad-slot="5996536534"\n     data-ad-format="auto"></ins>\n<script>\n(adsbygoogle = window.adsbygoogle || []).push({});\n</script>\n</div>\n                   <div class=\'col-xs-12\' style=\'border:solid 1px #333;text-align:center;\'></div>\n                                   <div class=\'col-xs-12\'><h3>When Is The Next Primary Election?</h3><p>\n \n    Primary elections and Caucuses are one means by which a political party \n     nominates candidates for the next general election.\n \n</p><ul class=\'list-group\'><li class=\'list-group-item\'>\n                         <a href=\'http://www.mytimetovote.com/2017-Primary-Election-Dates.html\'>\n                         2017 Primary Elections </a></li><li class=\'list-group-item\'>\n                         <a href=\'http://www.mytimetovote.com/2018-Primary-Election-Dates.html\'>\n                         2018 Primary Elections </a></li><li class=\'list-group-item\'>\n                         <a href=\'http://www.mytimetovote.com/2019-Primary-Election-Dates.html\'>\n                         2019 Primary Elections </a></li><li class=\'list-group-item\'>\n                         <a href=\'http://www.mytimetovote.com/2020-Primary-Election-Dates.html\'>\n                         2020 Primary Elections </a></li></ul></div> <div class=\'col-xs-12\'><h3>Breaking News Updates & Latest News Headlines </h3>\n                    <p>View the latest news and headline for U.S.,your state ...  \n                         <a href=\'http://feeds.mytimetovote.com/massachusetts.html\'>Check Latest News and Videos</a>\n                   </p></div> <div class=\'col-xs-12\'><h3>Am I eligible To Vote?</h3>\n                    <p>Most States require citizens to be registered in order to vote. Make sure you \n                          understand the voter registration requirements of your State of residence.\n                         <a href=\'http://canivote.mytimetovote.com/massachusetts.html#voterReg\'>Check if you are eligible to vote</a>\n                   </p></div> <div class=\'col-xs-12\'><h3>How Do I Register To Vote?</h3>\n                         <p>Check what options you have to register to vote in your state. \n                         <a href=\'http://canivote.mytimetovote.com/massachusetts.html#howtoReg\'>Click here for more information</a>\n                   </p></div> <div class=\'col-xs-12\'><h3>Where  Do I Register To Vote?</h3>\n                         <p>Don\'t wait, locate where you can register to vote, \n                           where to update your voter registration, or check your voter\n                          registration status and more\n                         <a href=\'http://polls.mytimetovote.com/massachusetts.html\'>Click here for more information</a>\n                   </p></div><div class=\'col-xs-12\'><h3>Can I Register To Vote At The Polls On Election Day?</h3>\n              <p>\n               Do you know if your state if one of the States that allow voters\n               to register at the polls on Election day? \n               <a href=\'http://canivote.mytimetovote.com/massachusetts.html#sdr\'>Click here for more information</a>\n            </p></div><div class=\'col-xs-12\'><h3>If My Address Has Changed Do I Need To Re-register To Vote?</h3>\n                <p>\n                  When you register to vote, your voter registration is linked to your residential address. When registered voters move, they are supposed to update their registration records with election officials before voting\n                <a href=\'http://canivote.mytimetovote.com/massachusetts.html#addressChanged\'>>>Check if you need to re-register to vote</a></p>\n              </div><div class=\'col-xs-12\'><h3>What\'s On The Ballot this year?</h3>\n                   <p>Find the offices that are up for election and\n                      public questions that will be on your ballot in the next election\n                   <a href=\'http://ballot.mytimetovote.com/massachusetts.html\'>Click here to see what will be on the statewide and local ballots</a>\n                </p></div><div class=\'col-xs-12\'><h3>Who Are My Elected Officials?</h3>\n                      <p>\n                        Find contact information for federal, state, and local government officials\n                        <a href=\'http://elections.mytimetovote.com/elected_officials/massachusetts.html\'>Click here to locate your elected officials</a>\n                      </p>\n                   </div> <div class=\'col-xs-12\'><h3>STATE OFFICIALS TERMS, AUTHORITY,SALARY, AND QUALITICATIONS</h3>\n                    <p>Do you know who\'s elected and who\'s appointed in your state? Or who can run for office? ...\n                         <a href=\'http://www.mytimetovote.com/massachusetts.html\'>Check Quickfacts about your state and state officials</a>\n                   </p></div><div class=\'col-xs-12\'><h3>What Political Parties Are There In My State?</h3>\n                      <p>\n                        Find contact information of qualified Political Parties in your state\n                        <a href=\'http://www.mytimetovote.com/Political-Parties/massachusetts.html\'>Click here to browse</a>\n                      </p>\n                   </div>\n                                                  </div>\n\n                        </div>\n\n  <div class=\'col-xs-12\' style=\'border:solid 1px #333;text-align:center;\' ></div> <div class="col-xs-12 col-sm-12" id="footer-block" >      <div id=\'footer-copyright\'>USA Elections -- COPYRIGHT 2017 www.mytimetovote.com all rights reserved</div> </div>\n  \n<!-- Start of StatCounter Code -->\n                     <script type="text/javascript">\n                       var sc_project=4155800;\n                       var sc_invisible=1;\n                       var sc_partition=51;\n                       var sc_click_stat=1;\n                       var sc_security="a9c7396f";\n                      </script> \n                     <script src="http://www.statcounter.com/counter/counter.js" type="text/javascript">\n                     </script>\n                     <noscript><div class="statcounter">\n                          <a target="_blank" href="http://www.statcounter.com/free_web_stats.html" title="website statistics">\n                            <img alt="website statistics" src="http://c.statcounter.com/4155800/0/a9c7396f/1/" class="statcounter"/></a></div></noscript>\n<!-- Start of StatCounter Code\n End of StatCounter Code -->\n<script type="text/javascript">var _gaq = _gaq || [];_gaq.push([\'_setAccount\', \'UA-34813453-1\']);\n  _gaq.push([\'_setDomainName\', \'mytimetovote.com\']);\n  _gaq.push([\'_trackPageview\']);\n  (function() {\n    var ga = document.createElement(\'script\'); ga.type = \'text/javascript\'; ga.async = true;\n    ga.src = (\'https:\' == document.location.protocol ? \'https://\' : \'http://\') + \'stats.g.doubleclick.net/dc.js\';\n    var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(ga, s);\n  })();</script>\n      <script>\ndocument.write(\'<script src="//sharebutton.net/plugin/sharebutton.php?type=vertical&u=\' + encodeURIComponent(document.location.href) + \'"></scr\' + \'ipt>\');\n</script>\n    \n\n  </div>\n\n\n                </div></body></html>'

Read the contents of your second webpage

Same deal as above, but now we're looking at your second URL.

In [8]:
p_2 = urllib.request.build_opener(urllib.request.HTTPCookieProcessor).open(url_2).read()
print(p_2)
b'<!DOCTYPE html>\n<!--[if IE 7]>\t\t\t\t\t<html class="ie7 no-js" lang="en">     <![endif]-->\n<!--[if lte IE 8]>              <html class="ie8 no-js" lang="en">     <![endif]-->\n<!--[if (gte IE 9)|!(IE)]><!--> <html class="not-ie no-js" lang="en">  <!--<![endif]-->\n<head>\n\t<meta charset="utf-8">\n\t<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">\t\n\t<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">\t\n\t\n<title>2017 Massachusetts Elections, Candidates, Races and Voting</title>\n<!-- 2017 Massachusetts Elections, Primary, Candidates, Races and Voting -->\n<meta name="keywords" content="massachusetts elections, massachusetts candidates, massachusetts state candidates, massachusetts local elections, massachusetts state elections, ma elections, ma local elections, ma state elections" />\n<meta name="description" content="Directory of Massachusetts elections. Massachusetts candidates for Governor, state reps and Congress (Senators / House of Representatives). MA primary and election races. Voting info. MA political parties. MA state election office." />\n<!-- Massachusetts elections, Massachusetts candidates, primary and caucus calendar, campaign websites, politics and more.  -->\n\n\t<link rel="shortcut icon" type="image" href="https://uselections.com/favicon.ico" />\n\t\n\t<link rel="stylesheet" type="text/css" href="https://uselections.com/css/style.css" />\n\t<!-- <link rel="stylesheet" type="text/css" href="fancybox/jquery.fancybox.css" /> -->\n\n\t<!-- HTML5 Shiv -->\n\t<!-- <script type="text/javascript" src="//uselections.com/js/modernizr.custom.js"></script> -->\n \n \t<!-- Google Analytics -->\n <script type="text/javascript">\n  var _gaq = _gaq || [];\n  _gaq.push([\'_setAccount\', \'UA-28809794-3\']);\n  _gaq.push([\'_setDomainName\', \'.uselections.com\']);\n  _gaq.push([\'_trackPageview\']);\n\n  (function() {\n    var ga = document.createElement(\'script\'); ga.type = \'text/javascript\'; ga.async = true;\n    ga.src = (\'https:\' == document.location.protocol ? \'https://ssl\' : \'http://www\') + \'.google-analytics.com/ga.js\';\n    var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(ga, s);\n  })();\n</script>   \n\n<!-- Google Page Level Ads -->\n<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>\n<script>\n  (adsbygoogle = window.adsbygoogle || []).push({\n    google_ad_client: "ca-pub-3927222402214627",\n    enable_page_level_ads: true\n  });\n</script>\n<!-- End -->\n     \n</head>\n<body class="style-1">\n\t\n<div class="wrap-header"></div><!--/ .wrap-header-->\n\n<div class="wrap">\n\t\n<!--ZOOMSTOP-->\n\t<!-- - - - - - - - - - - - - - Header - - - - - - - - - - - - - - - - -->\t\n\t\n\t<header id="header" class="clearfix">\n    \n    <div align="center"><div style="height:123px; width:auto;"><a href="https://uselections.com"><img src="https://uselections.com/images/USE-logo-boonex.png" alt="US Elections" title="US Elections" style="padding: 8px 0 7px" /></a></div></div>\n   \n\n\t\t<nav id="navigation" class="navigation">\n\t\t\t\n\t\t\t<ul>\n\t\t\t\t<li><a href="https://uselections.com/">Home</a></li>\n\t\t\t\t<li><a href="https://uselections.com/uselections/">Elections & Voting</a>\n\t\t\t\t\t<ul>\n                        <li><a href="https://uselections.com/results/">Election Results</a></li>\n                        <li><a href="https://uselections.com/calendar-us-elections.shtml">Election Calendar</a></li>\n                        <li><a href="https://uselections.com/pres.htm">President</a></li>\n\t\t\t\t\t\t<li><a href="https://uselections.com/uselections/">50 States</a></li>\n                        <li><a href="https://uselections.com/qanda.htm">Voting</a></li>\n                        <li><a href="https://uselections.com/us-congressional-district-map.shtml">Find Your District</a></li>\n\t\t\t\t\t\t<li><a href="https://uselections.com/usa_localities/">Find Your Home Town</a></li>\n\t\t\t\t\t\t<li><a href="https://uselections.com/parties.htm">National Parties</a></li>\n\t\t\t\t\t</ul>\n\t\t\t\t</li>      \n                <li><a href="https://uselections.com/m/answers/home/">FAQ / Answers</a></li>\n                <li><a href="https://uselections.com/page/GoodLife200" target="_blank">Free $200 Card</a></li>\n            <li><a href="https://uselections.com/m/google_search/">Search</a></li>\n            <li><a href="https://uselections.com/m/answers/home/">Contact Me</a>\n                <ul>\n                        <li><a href="https://uselections.com/submissions/Submissions/politicians.php" onclick="window.open(\'https://uselections.com/submissions/Submissions/politicians.php\',\'popup\',\'width=550,height=550,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0\'); return false">Candidate Submissions</a></li>\n\t\t\t\t\t\t<li><a href="https://uselections.com/contact.php">Contact Me</a></li>\n\t\t\t\t</ul>\n                </li>\n                <!-- <li><a href="https://uselections.com/join.php">JOIN!</a></li> -->\n\t\t\t</ul>\n\t\t\t\n\t\t</nav><!--/ #navigation-->\n\t\t\n\t</header><!--/ #header-->\n\t\n\t<!-- - - - - - - - - - - - - - end Header - - - - - - - - - - - - - - - - -->\t\n<!--ZOOMRESTART-->\t\n\t\n\t\n\t<!-- - - - - - - - - - - - - - - Container - - - - - - - - - - - - - - - - -->\t\n\t\n\t<section class="container sbr clearfix">\n\t\t\n\t\t<!-- - - - - - - - - - Page Header - - - - - - - - - - -->\t\n\t\t\n\t\t<div class="page-header">\n\t\t\t\n<div align="center">\n<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>\n<!-- USE1-R -->\n<ins class="adsbygoogle"\n     style="display:block"\n     data-ad-client="ca-pub-3927222402214627"\n     data-ad-slot="3861224604"\n     data-ad-format="auto"></ins>\n<script>\n(adsbygoogle = window.adsbygoogle || []).push({});\n</script>\n</div>\n\t\t\t\n\t\t</div><!--/ .page-header-->\n\t\t\n\t\t<!-- - - - - - - - - end Page Header - - - - - - - - - -->\t\n\t\t\n\n\t\t<!-- - - - - - - - - - - - - - - Content - - - - - - - - - - - - - - - - -->\t\t\n\t\t\n\t\t<section id="content">\n\t\t\t\n\t\t\t<article class="post clearfix">\n\t\t\t\t\n                <h1 class="page-title">US Elections ~ Massachusetts</h1>\n                \n\t\t\t\t<h3 class="title">Directory of Massachusetts elections. Massachusetts candidates for Governor, state reps and Congress (Senators / House of Representatives). MA primary and election races. Voting info. Political parties. State election office.</h3>\n\t\t\t\t<!--/ .title -->\n\t\t\t\t\n\t\t\t\t<section class="post-meta clearfix">\n\t\t\t\t\t\n\t\t\t\t\t<div class="post-date"><a href="#">October 21, 2017 (last updated)</a></div><!--/ .post-date-->\n\t\t\t\t\t<div class="post-tags">\n\t\t\t\t\t\t<a href="https://uselections.com/news-us-elections.shtml">News</a>\n                        <a href="https://uselections.com/calendar-us-elections.shtml">Calendar</a>\n\t\t\t\t\t\t<a href="ma-localities.shtml">Massachusetts (Find Your Home Town)</a> \n\t\t\t\t  </div><!--/ .post-tags-->\n\t\t\t\t\t\n\t\t\t\t</section><!--/ .post-meta-->\n\n<br><p align="left">\n<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>\n<!-- USEBoonexLinks -->\n<ins class="adsbygoogle"\n     style="display:block"\n     data-ad-client="ca-pub-3927222402214627"\n     data-ad-slot="9868824203"\n     data-ad-format="link"></ins>\n<script>\n(adsbygoogle = window.adsbygoogle || []).push({});\n</script>\n</p>\n\t\t\t\t\n\t\t\t\t<p><a href="https://uselections.com/us-congressional-district-map.shtml">\n\t\t\t\t\t<img class="custom-frame" alt="massachusetts election congressional districts" src="../images/states/MA550w.png">\n\t\t\t\t</a></p>\n                \n<!-- AddThis Button BEGIN -->\n<br />\n<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=launch3" async="async"></script>\n<div class="addthis_sharing_toolbox"></div>\n<!-- AddThis Button END -->\n<br />\n<div align="left">\n<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>\n<!-- USEBoonexLinks -->\n<ins class="adsbygoogle"\n     style="display:block"\n     data-ad-client="ca-pub-3927222402214627"\n     data-ad-slot="9868824203"\n     data-ad-format="link"></ins>\n<script>\n(adsbygoogle = window.adsbygoogle || []).push({});\n</script>\n</div>\n<br />\n                  \n\t\t\t\t<p class="notice"><strong><span class="usetitle"><u>Election, Primary &amp; Filing Dates</u>:</span><br>\n                    <br>\n                State Primary: TBD<br>\nFiling Deadline:<br>\n&nbsp;\n~ TBD (Major Parties)<br />\n&nbsp;\n~ TBD</strong> <strong>(Third Parties &amp; Independents)</strong></p>\n\n<p class="info"><strong><span class="usetitle"><u>$200 FREE. A Gift From Me.</u><br>&nbsp;&nbsp;&nbsp;</span></strong><br>\n<strong>Save up to $200 at over 1 MILLION hotels, resorts &amp; condos. Free savings card. </strong><u>Yes, it\'s a REAL $200</u>! Everyone loves \'em. Get it now, use it later. <strong>Save $$$</strong> on your next vacation, getaway or trip. <a href="https://uselections.com/page/GoodLife200">Grab one now before they\'re gone!</a><br>\n<em>- Jeff Cohen, Founder @ USelections.com</em></p>\n\n<p class="notice"><strong><span class="usetitle"><u>Voter Information</u>:<br>\n&nbsp;&nbsp;&nbsp;</span></strong><br>\nFor eligibility &amp; identification requirements, dates, deadlines, voting materials, contact info and more: <strong><a href="https://www.usvotefoundation.org/vote/sviddomestic.htm" target="_blank">[ click here ]</a></strong>.<br>\nAll important election dates &amp; deadlines for voters: <strong><a href="https://www.usvotefoundation.org/vote/state-elections/state-election-dates-deadlines.htm" target="_blank">[ click here ]</a></strong>.<br>\n\t\t&nbsp;&nbsp;&nbsp;&nbsp;<br>\n<strong><span class="usetitle"><u>Poll Opening &amp; Closing Times</u>:<br>\n&nbsp;&nbsp;&nbsp;</span></strong><br>\nIn the state of Massachusetts, most polling places are open from <strong>7:00 AM to 8:00 PM</strong> Eastern Time. However, municipalities may open as early as 5:45 AM. All polling places must remain open for at least 13 hours.</p>\n\n<div align="left">\n<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>\n<!-- USE2 -->\n<ins class="adsbygoogle"\n     style="display:inline-block;width:336px;height:280px"\n     data-ad-client="ca-pub-3927222402214627"\n     data-ad-slot="4813183199"></ins>\n<script>\n(adsbygoogle = window.adsbygoogle || []).push({});\n</script>                  \n</div><br /> \n\t\t\t  \n<p>\n  <span class="usenextelect">Next State Constitutional Officer Elections in 2018. </span> </p>\n<p><span class="usetitle">Massachusetts Governor:</span><br />\n  <span class="use3point"><a href="http://www.mass.gov/governor/"><strong>Charlie Baker (R)</strong></a> | <a href="http://www.charliebaker2014.com">Campaign Website</a><a href="http://www.mass.gov/?pageID=gov3homepage&amp;L=1&amp;L0=Home&amp;sid=Agov3"></a></span></p>\n<table class="center">\n  <tr>\n    <td class="success"><p><font class="candidates"><strong><u>Election Race  Candidates:</u></strong></font></p>\n      <ul>\n        <li class="use2point"><strong><a href="http://www.facebook.com/ronaldbeatyjr">Ron Beaty (R)</a>\xc2\xa0<br>\n          </strong>~ Barnstable County Commissioner, Tea Party Activist, Felon</li>\n        <li class="use2point"><a href="http://jay4ma.com/"><strong>Jay Gonzalez (D)</strong></a><strong><br>\n        </strong>~ Attorney, Ex-State Finance Secretary, Ex-Health Care Executive</li>\n        <li class="use2point"><strong><a href="http://www.facebook.com/bob.massie">Bob Massie (D)</a>\xc2\xa0<br>\n          </strong>~ Minister, University Official, Social Activist</li>\n        <li class="use2point"><strong><a href="http://settiwarren.com/">Setti Warren (D)</a>\xc2\xa0<br>\n          </strong>~ Newton Mayor, Ex-Clinton White House Aide, Iraq War Veteran</li>\n      </ul></td>\n  </tr>\n  <tr>\n    <td height="30"></td>\n  </tr>\n</table>\n<p><span class="usetitle"> Massachusetts Lieutenant Governor:</span><br>\n  <a href="http://www.mass.gov/governor/" class="use3point"><strong>Karyn Polito (R)</strong></a></p>\n<p><span class="usetitle">Massachusetts&nbsp; Attorney General:</span><br />\n  <span class="use3point"><strong><a href="http://www.state.ma.us/ag/">Maura Healey (D)</a></strong> | <a href="http://www.maurahealey.com/">Campaign Website</a></span></p>\n<p><span class="usetitle">Massachusetts&nbsp;Secretary of the Commonwealth:</span><br />\n  <span class="use3point"><strong><a href="http://www.sec.state.ma.us/">Bill Galvin (D)</a></strong> | <a href="http://www.billgalvin.org/">Campaign Website</a></span></p>\n<table class="center">\n  <tr>\n    <td class="success"><p><font class="candidates"><strong><u>Election Race  Candidates:</u></strong></font></p>\n      <ul>\n        <li class="use2point"><strong><a href="https://www.attorneyjaymcmahon.com/">Jay McMahon (R)</a>\xc2\xa0<br>\n          </strong>~ Attorney, National Guard Veteran\xc2\xa0</li>\n        <li class="use2point"><strong><a href="http://www.danshores.com/">Dan Shores (R)</a>\xc2\xa0<br>\n        </strong>~ Attorney</li>\n      </ul></td>\n  </tr>\n  <tr>\n    <td height="30"></td>\n  </tr>\n</table>\n<p><span class="usetitle">Massachusetts State Treasurer &amp; Receiver-General:</span><br />\n  <span class="use3point"><strong><a href="http://www.state.ma.us/treasury/">Deb Goldberg (D)</a></strong><a href="http://www.state.ma.us/treasury/"> </a>| <a href="http://www.debgoldberg.com">Campaign Website</a></span></p>\n<p><span class="usetitle">Massachusetts State Auditor:</span><br />\n  <span class="use3point"><a href="http://www.mass.gov/sao/"><strong>Suzanne Bump (D)</strong></a> | <a href="http://www.suzannebump.com/">Campaign Website</a></span></p>\n\n<!-- <p>\n<div align="left">\n<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>\n<ins class="adsbygoogle"\n     style="display:inline-block;width:336px;height:280px"\n     data-ad-client="ca-pub-3927222402214627"\n     data-ad-slot="4813183199"></ins>\n<script>\n(adsbygoogle = window.adsbygoogle || []).push({});\n</script>                  \n</div> -->\n<p></p>\n\n<p class="notice"><strong><span class="usetitle">General Court of Massachusetts<br>\n  (State Legislature):</span><br>\n  <br>\n  <strong><span class="use3point"><span class="use2point"><img src="../images/bullet-arrow-right-orange.png"></span></span> <a href="http://www.malegislature.gov/">General Court</a><br>\n  <span class="use3point"><span class="use2point"><img src="../images/bullet-arrow-right-orange.png"></span></span> <a href="http://www.malegislature.gov/People/Senate">Senate</a><br>\n    </strong></strong>Massachusetts has 40 State Senate members: 343 (Democrats), 6 (Republicans).<br>\n  Length of term: 2 years.<strong><br>\n  <span class="use3point"><span class="use2point"><img src="../images/bullet-arrow-right-orange.png"></span></span> <a href="http://www.malegislature.gov/People/House">House of Representatives</a><br>\n  </strong>Massachusetts has 160 State House members: 125 (Democrats), 35 (Republicans).<br>\n  Length of term: 2 years</p>\n<p align="center"><img src="../images/states/MAseal.png" alt="massachusetts state seal"></p>\n<p class="notice"><strong><span class="usetitle">2018 | <u>On</u> <u>Your</u> <u>Ballot</u>:</span></strong><br>\n  <br>\n<strong><img src="../images/bullet-arrow-right-orange.png"> </strong>See the <strong>2018 Massachusetts Races, Court Judges &amp; Ballot Measures</strong> you will be voting on: <strong><a href="http://onyourballot.vote411.org/" target="_blank">[ click here ]</a></strong>.<br>\n- Includes <u>all</u> your federal, state and local races.<u><br><em>NOTE:</em></u><em> Type in your address, then click &quot;Check My Races.&quot; This will list everything to appear on your ballot this year.</em></p>\n<p class="notice"><strong><span class="usetitle">What\'s My District?</span></strong><br>\n<br>\n<strong><img src="../images/bullet-arrow-right-orange.png"></strong> To see which US Congressional district you live in: <strong><a href="https://uselections.com/us-congressional-district-map.shtml">[ click here ]</a></strong>.<br>\n<strong><img src="../images/bullet-arrow-right-orange.png"></strong> <strong>What are my local districts?</strong> Visit your county, parish, city or town websites: <strong><a href="https://uselections.com/usa_localities/">[ click here ]</a></strong>.</p>\n<!-- - - - - - - - - in text ad #1 - - - - - - - - - -->\t\n<p>&nbsp;&nbsp;&nbsp;</p>              \n<!--<div align="left"><a href="https://GoodLifeNation.com" target="_blank"><img src="https://uselections.com/images/goodlife/goodlife-ad-550w.png" alt="" border="0" /></a></div>-->\n<div align="left"><a href="http://uselections.com/go/LostWays" target="_blank"><img src="https://uselections.com/images/affiliate/lostways1.png" alt="" border="0" /></a></div>\n<!-- <br /><br />\n<div align="left"><a href="http://uselections.com/go/Pemmican" target="_blank"><img src="https://uselections.com/images/affiliate/intextad3.png" alt="Pemmican" border="0" /></a></div>--><p>&nbsp;&nbsp;&nbsp;</p>\n<!-- - - - - - - - - end  - - - - - - - - - -->\t\n<p class="usetitle">U.S. Senators:<br>\n  <span class="use3point">(Terms are <u>6 years</u> in length) </span></p>\n<p class="use2point"><a href="http://warren.senate.gov/"><strong>Elizabeth Warren (D)</strong></a> | <a href="http://www.elizabethwarren.com/">Campaign Website</a><br>\n  Has been in office since: 2013<br />\n  <strong>* Next Election 2018.</strong></p>\n<table class="center">\n  <tr>\n    <td class="success"><p><font class="candidates"><strong><u>Senate  Candidates:</u></strong></font></p>\n      <ul>\n        <li class="use2point"><strong><a href="http://shiva4senate.com/">Shiva Ayyadurai (R)</a>\xc2\xa0<br>\n          </strong>~ Computer Systems Scientist, Businessman<strong><br>\n            </strong></li>\n        <li class="use2point"><strong><a href="http://www.diehlforsenate.com/">Geoff Diehl (R)</a>\xc2\xa0<br>\n          </strong>~ State Representative, Businessman</li>\n        <li class="use2point"><strong><a href="https://johnkingston.com/">John Kingston (R)</a>\xc2\xa0<br>\n          </strong>~ Businessman, Attorney, Philanthropist, GOP Fundraiser<strong><br>\n          </strong></li>\n        <li class="use2point"><strong><a href="http://bethforsenate.com/">Beth Lindstrom\xc2\xa0(R) </a><br>\n          </strong>~ Businesswoman, Political Consultant, Ex-State Lottery Director\xc2\xa0</li>\n        <li class="use2point"><strong><a href="http://www.facebook.com/DariusMitchell4USSenate/">Darius Mitchell (R)</a></strong></li>\n        <li class="use2point"><strong><a href="http://www.allenrwaters.com/">Allen Waters (R)</a>\xc2\xa0<br>\n        </strong>~ Financial Consultant</li>\n        <li class="use2point"><strong><a href="http://heidiforsenate.com/">Heidi Wellman (R)</a>\xc2\xa0<br>\n          </strong>~ Risk Manager, Libertarian Party Activist</li>\n        <li class="use2point"><strong><a href="http://www.facebook.com/JoshuaFordMass/">Joshua Ford (United Independent)</a>\xc2\xa0<br>\n          </strong>~ Police Officer, Sanders Campaign Activist</li>\n        <li class="use2point"><strong><a href="https://www.newswire.com/news/john-p-devine-for-united-states-senate-19331789">John Devine (Independent)</a><br>\n          </strong>~ Risk Assessment Consultant</li>\n      </ul></td>\n  </tr>\n  <tr>\n    <td height="30"></td>\n  </tr>\n</table>\n<p class="use2point"><strong><a href="http://markey.senate.gov/">Ed Markey (D)</a></strong> | <a href="http://www.edmarkey.org/">Campaign Website</a><strong><br>\n  </strong>Has been in office since: 2013  <strong><br />\n* Next Election 2020.</strong></p>\n<p>&nbsp;&nbsp;&nbsp;</p>\n<p class="usetitle">U.S. House Of Representatives:<br>\n  <span class="use3point">(Terms are <u>2 years</u> in length) </span></p>\n\n<p><span class="usetitle">District 1:</span><br />\n  <span class="use2point"><a href="http://www.house.gov/neal/"><strong>Richard Neal (D)</strong></a> | <a href="http://www.nealforcongress.com/">Campaign                   Website</a></span> &nbsp; <br>\n  <span class="use2point">Has been in office since: 1989</span></p>\n<p><span class="usetitle">District 2:</span><br />\n  <span class="use2point"><strong><a href="http://mcgovern.house.gov/">Jim McGovern (D)</a></strong> | <a href="http://www.jimmcgovern.com/">Campaign Website</a></span> &nbsp; <br>\n  <span class="use2point">Has been in office since: 1989</span></p>\n<table class="center">\n  <tr>\n    <td class="success"><p><font class="candidates"><strong><u>2nd District  Candidates:</u></strong></font></p>\n      <ul>\n        <li class="use2point"><strong><a href="http://www.domwarren.com/">Dom Warren (D)</a>\xc2\xa0<br>\n          </strong>~ Community Activist</li>\n        <li class="use2point"><strong><a href="http://www.sossapaquette2018.org/">Jeffrey Sossa-Paquette (R)</a><br>\n          </strong>~ Businessman <strong><br>\n          </strong></li>\n        <li class="use2point"><strong><a href="http://www.facebook.com/Paul-V-Grady-for-US-Congress-Ma-District-2-240496019740090/">Paul Grady (Independent)</a>\xc2\xa0<br>\n          </strong>~ Hydrogeological Contractor</li>\n      </ul></td>\n  </tr>\n  <tr>\n    <td height="30"></td>\n  </tr>\n</table>\n<p><span class="usetitle">District 3:</span><br />\n  <span class="use2point"><strong><a href="http://tsongas.house.gov/">Niki Tsongas (D)</a></strong><br>\n  * Retiring in 2018.</span><br>\n  <span class="use2point">Has been in office since: 2007</span></p>\n<table class="center">\n  <tr>\n    <td class="success"><p><font class="candidates"><strong><u>3rd District  Candidates:</u></strong></font></p>\n      <ul>\n        <li class="use2point"><strong><a href="http://beejdas.com/">Abhijit "Beej" Das (D)</a>\xc2\xa0<br>\n          </strong>~ Hotel Company CEO<strong>\xc2\xa0</strong></li>\n        <li class="use2point"><strong><a href="http://twitter.com/stevekerrigan">Steve Kerrigan (D)</a>\xc2\xa0<br>\n          </strong>~ 2013 Presidential Inauguration Committee CEO, Ex-Lancaster Selectman</li>\n        <li class="use2point"><strong><a href="http://twitter.com/dank">Dan Koh (D)</a>\xc2\xa0<br>\n        </strong>~ Ex-Boston Mayoral Chief of Staff, Ex-Huffington Post Executive</li>\n        <li class="use2point"><strong><a href="http://teambarbara.com/">Barbara L\xe2\x80\x99Italien (D)</a>\xc2\xa0<br>\n          </strong>~ State Senator, Social Worker, Ex-State Representative, Ex-Andover School Board Member</li>\n        <li class="use2point"><strong><a href="https://www.juanamatias.com/">Juana Matias (D)</a>\xc2\xa0<br>\n          </strong>~ State Representative, Attorney, AmeriCorps Veteran</li>\n        <li class="use2point"><strong><a href="http://www.votenadeem.com/">Nadeem Mazen (D)</a>\xc2\xa0<br>\n          </strong>~ Cambridge City Councillor, Businessman, Engineer</li>\n        <li class="use2point"><strong>Terry Ryan (D) <br>\n          </strong>~ Westford School Board Chair, Businessman, Engineer</li>\n        <li class="use2point"><strong><a href="https://www.crowdpac.com/campaigns/343136/lori-trahan">Lori Trahan (D)</a>\xc2\xa0<br>\n          </strong>~ Business Consultant, Ex-Congressional Aide</li>\n        <li class="use2point"><a href="http://twitter.com/rickgreenma"><strong>Rick Green (R)</strong></a>\xc2\xa0<br>\n          ~ Auto Parts Company Owner</li>\n        <li class="use2point"><strong><a href="http://www.change4mass.com/">Scott Gunderson (R)</a>\xc2\xa0<br>\n        </strong>~ Businessman, Retired Naval Officer, Iraq War Veteran</li>\n        <li class="use2point"><strong>Louis Marino (R)</strong></li>\n      </ul></td>\n  </tr>\n  <tr>\n    <td height="30"></td>\n  </tr>\n</table>\n<p><span class="usetitle">District 4:</span><br />\n  <span class="use2point"><a href="http://kennedy.house.gov/"><strong>Joe Kennedy III (D)</strong></a> | <a href="http://www.joekennedyforcongress.com/">Campaign Website</a></span> &nbsp; <br>\n  <span class="use2point">Has been in office since: 2013</span></p>\n<p><span class="usetitle">District 5:</span><br />\n  <span class="use2point"><strong><a href="http://katherineclark.house.gov/">Katherine Clark (D)</a></strong> | <a href="http://katherineclark.org/">Campaign Website</a> &nbsp; <br>\n  Has been in office since: 2013</span></p>\n<p><span class="usetitle">District 6:</span><br />\n  <span class="use2point"><strong><a href="http://moulton.house.gov/">Seth Moulton  (D)</a></strong> | <a href="http://www.sethmoulton.com/">Campaign Website</a></span> &nbsp; <br>\n  <span class="use2point">Has been in office since: 2015</span></p>\n<table class="center">\n  <tr>\n    <td class="success"><p><font class="candidates"><strong><u>6th District  Candidates:</u></strong></font></p>\n      <ul>\n        <li class="use2point"><strong><a href="http://carlosarmandohernandez.com/">Carlos Hernandez (R)</a>\xc2\xa0<br>\n          </strong>~ IT Consultant, Insurance Broker, Navy Veteran, Tea Party Activist</li>\n        <li class="use2point"><strong><a href="http://samsonforcongress.com/">Sam Racioppi (Libertarian)</a>\xc2\xa0<br>\n          </strong>~ Computer Consultant, Army Veteran</li>\n      </ul></td>\n  </tr>\n  <tr>\n    <td height="30"></td>\n  </tr>\n</table>\n<p><span class="usetitle">District 7:</span><br />\n  <span class="use2point"><strong><a href="http://www.house.gov/capuano/">Mike Capuano (D)</a></strong> | <a href="http://www.mikecapuano.com/">Campaign Website</a></span> &nbsp; <br>\n  <span class="use2point">Has been in office since: 1999</span></p>\n<p><span class="usetitle">District 8:</span><br />\n  <span class="use2point"><strong><a href="http://www.house.gov/lynch/">Stephen Lynch (D)</a></strong> | <a href="http://www.stephenlynchforcongress.com/">Campaign Website</a></span> &nbsp; <br>\n  <span class="use2point">Has been in office since: 2001 </span></p>\n<table class="center">\n  <tr>\n    <td class="success"><p><font class="candidates"><strong><u>8th District  Candidates:</u></strong></font></p>\n      <ul>\n        <li class="use2point"><strong><a href="http://electchristopher.com/">Christopher Voehl (D)</a>\xc2\xa0<br>\n          </strong>~ Pilot</li>\n        <li class="use2point"><strong><a href="https://briannawu2018.com/">Brianna Wu (D)</a>\xc2\xa0<br>\n        </strong>~ Software Game Developer</li>\n      </ul></td>\n  </tr>\n  <tr>\n    <td height="30"></td>\n  </tr>\n</table>\n<p><span class="usetitle">District 9:</span><br />\n  <span class="use2point"><strong><a href="http://keating.house.gov/">Bill Keating (D)</a></strong> | <a href="http://www.billkeating.org/">Campaign Website</a></span> &nbsp; <br>\n  <span class="use2point">Has been in office since: 2011</span></p>\n<table class="center">\n  <tr>\n    <td class="success"><p><font class="candidates"><strong><u>9th District  Candidates:</u></strong></font></p>\n      <ul>\n        <li class="use2point"><strong><a href="http://tedeschiforcongress.com/">Peter Tedeschi (R)</a>\xc2\xa0<br>\n          </strong>~ Businessman</li>\n      </ul></td>\n  </tr>\n  <tr>\n    <td height="30"></td>\n  </tr>\n</table>\n<p>&nbsp;&nbsp;&nbsp;</p>\n<p align="center"><img src="../images/states/MAflag.png" alt="massachusetts state flag"></p>\n<!-- - - - - - - - - in text ad #2 - - - - - - - - - -->\t\n<p>&nbsp;&nbsp;&nbsp;</p>              \n<div align="left"><a href="http://uselections.com/go/BulletproofHome" target="_blank"><img src="https://uselections.com/images/affiliate/intextad1.png" alt="" border="0" /></a></div>\n<br /><br />\n<div align="left"><a href="http://uselections.com/go/LostWays" target="_blank"><img src="https://uselections.com/images/affiliate/lostways4.png" alt="" border="0" /></a></div><p>&nbsp;&nbsp;&nbsp;</p>\n<!-- - - - - - - - - end  - - - - - - - - - -->\t\n<p class="notice">\n<span class="usetitle">Massachusetts Election Office:</span><br>\n<br>\n<img src="../images/bullet-arrow-right-orange.png"> <strong><a href="http://www.state.ma.us/sec/ele/eleidx.htm">Massachusetts Election Division</a></strong><a href="http://www.state.ma.us/sec/ele/eleidx.htm"></a>\n  <br>\n  (Get voter registration &amp; information. Polling places and times. Absentee  voting. Ballot measures. District maps. Massachusetts election FAQ.)</p>\n<p class="notice">\n<span class="usetitle">Massachusetts Political Parties:</span>\n<br>\n<br>\n<img src="../images/bullet-arrow-right-orange.png"> <a href="http://www.constitutionalview.org/">Constitution Party of Massachusetts</a><br />\n<img src="../images/bullet-arrow-right-orange.png"> <a href="http://www.massdems.org/">Massachusetts Democratic Party</a><br />\n<img src="../images/bullet-arrow-right-orange.png"> <a href="http://www.green-rainbow.org/">Massachusetts Green-Rainbow Party</a><br />\n<img src="../images/bullet-arrow-right-orange.png"> <a href="http://lpmass.org/">Libertarian Party of Massachusetts</a><br />\n<img src="../images/bullet-arrow-right-orange.png"> <a href="http://www.massgop.com/">Massachusetts Republican Party</a><br />\n<img src="../images/bullet-arrow-right-orange.png"> <a href="http://www.spmassachusetts.org/">Socialist Party of Massachusetts</a></p>\n<p class="notice">\n                  <span class="usetitle">Find Your Home Town | Localized Massachusetts Election Information:</span>\n                  <br>\n                  <br>\n                  <img src="../images/bullet-arrow-right-orange.png"> <a href="ma-localities.shtml">Find Your Home Town: Cities, Towns and County Directory</a></p>\n<p class="info"><strong><span class="usetitle"><u>Save $200 On Hotels &amp; Resorts</u>:<br>&nbsp;&nbsp;&nbsp;</span></strong><br>\n<strong>It\'s my gift to you for a limited time! Grab your FREE $200 card from USelections.com before they\'re gone. </strong>Get now. Use later. You don\'t want to miss out on getting a card. It\'s awesome. <strong>{ <a href="https://uselections.com/page/GoodLife200" target="_blank">Click Here</a> }</strong></p>\n<!-- - - - - - - - - bottom insert - - - - - - - - - -->\t            \n<div align="left"><a href="http://uselections.com/go/PatriotPrivacy" target="_blank"><img src="https://uselections.com/images/affiliate/intextad2.png" alt="" border="0" /></a></div>\n<!-- - - - - - - - - end  - - - - - - - - - -->\t \n\t\t  </article>\n\t\t\t<!--/ .post-->\n\n\t\t</section><!--/ #content-->\n\t\t\n\t\t<!-- - - - - - - - - - - - - - end Content - - - - - - - - - - - - - - - - -->\t\n\t\t\n<!--ZOOMSTOP-->\n<!-- - - - - - - - - - - - - - - Sidebar - - - - - - - - - - - - - - - - -->\n    <aside id="sidebar">\n    \n    <div class="widget-container">\n<!--/ google site search -->\n<script>\n  (function() {\n    var cx = \'004503200095547316544:ibmdqaxbb0k\';\n    var gcse = document.createElement(\'script\');\n    gcse.type = \'text/javascript\';\n    gcse.async = true;\n    gcse.src = \'https://cse.google.com/cse.js?cx=\' + cx;\n    var s = document.getElementsByTagName(\'script\')[0];\n    s.parentNode.insertBefore(gcse, s);\n  })();\n</script>\n<gcse:searchbox-only></gcse:searchbox-only>\n<!--/ end google site search -->\n\t\t\t\n\t\t\t</div><!--/ .widget-container-->  \n      <div align="center">\n<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>\n<!-- USE3side -->\n<ins class="adsbygoogle"\n     style="display:inline-block;width:300px;height:250px"\n     data-ad-client="ca-pub-3927222402214627"\n     data-ad-slot="7436465009"></ins>\n<script>\n(adsbygoogle = window.adsbygoogle || []).push({});\n</script></div> <br /><br />\n\n <div align="center"><script type="text/javascript" src="//ap.lijit.com/www/delivery/fpi.js?z=450286&width=300&height=250"></script></div>\n      <br />\n      <br />\n      \n<!--/ .widget-container-->\n<div class="widget-container widget_popular_posts">\n        <h3 class="widget-title">Election Races: Who\'s In. Who\'s Out.</h3>\n        <ul> \n             <li><a href="https://uselections.com/pa/pa.htm">PENNSYLVANIA District 7: Paul Perry (D) exits race vs Congressman Pat Meehan (R) (weak fundraising). District 15: Marty Nothstein (R) enters the open seat congressional race.</a>\n             <span class="widget-date">October 20, 2017</span></li>\n             <li><a href="https://uselections.com/in/in.htm">INDIANA District 2: Yatish Joshi (D) enters race vs Congresswoman Jackie Walorski (R).</a>\n             <span class="widget-date">October 20, 2017</span></li>\n             <li><a href="https://uselections.com/ga/ga.htm">GEORGIA District 6: Kevin Abel (D) enters race vs Congresswoman Karen Handel (R).</a>\n             <span class="widget-date">October 20, 2017</span></li>\n             <li><a href="https://uselections.com/ca/ca.htm">CALFORNIA District 52: Jeff Cullen (R) enters race vs Congressman Scott Peters (D).</a>\n             <span class="widget-date">October 20, 2017</span></li>\n             <li><a href="https://uselections.com/tx/tx.htm">TEXAS District 21: Foster Hagen (R) enters race vs Congressman Lamar Smith (R).</a>\n             <span class="widget-date">October 20, 2017</span></li>\n             <li><a href="https://uselections.com/nh/nh.htm">NEW HAMPSHIRE District 1: Lincoln Soldati (D) enters the open seat congressional race.</a>\n             <span class="widget-date">October 19, 2017</span></li>\n             <li><a href="https://uselections.com/ma/ma.htm">MASSACHUSETTS District 9: Peter Tedeschi (R) to run vs Congressman Bill Keating (D).</a>\n             <span class="widget-date">October 19, 2017</span></li>\n             <li><a href="https://uselections.com/ny/ny.htm">NEW YORK District 21: Tanya Boone (D) enters race vs Congresswoman Elise Stefanik (R).</a>\n             <span class="widget-date">October 19, 2017</span></li>\n        <li> <a href="https://uselections.com/">See More Recent News...</h6></a> </li>\n        </ul>\n</div>\n\n <div align="center"><script type="text/javascript" src="//ap.lijit.com/www/delivery/fpi.js?z=287836&width=300&height=250"></script></div><br /> \n<div align="center"><a title="goodlife usa" href="https://uselections.com/page/GoodLife200"><img style="border: 0;" src="https://uselections.com/images/goodlife/VIP-300x250.jpg" /></a></div>\n<br />\n<!-- <div align="center"><a href="http://uselections.com/go/Pemmican" target="_blank"><img src="https://uselections.com/images/affiliate/pemmican2.jpg" border="0" /></a></div><br /><br /> -->\n      <!--/ .widget-container-->\n<div class="widget-container widget_categories">\n        <h3 class="widget-title">Latest Topics</h3>\n        <ul>\n          <li><strong>Q & A:</strong> <a href="https://uselections.com/m/answers/view/What-is-the-difference-between-a-primary-caucus-and-convention">What is the difference between a primary, caucus and convention?</a></li>\n          <li><strong>Q & A:</strong> <a href="https://uselections.com/m/answers/view/Can-a-Dem-Rep-primary-losing-candidate-run-as-a-third-party-candidate">Can a Democrat / Republican primary losing candidate run as a third party candidate?</a></li>\n          <li><strong>Q & A:</strong> <a href="https://uselections.com/m/answers/view/Is-electorate-required-to-adhere-to-the-popular-vote">Is the electorate required to adhere to the popular vote?</a></li>\n          <li><strong>SITES:</strong> <a href="https://uselections.com/m/sites/home/">Solution oriented & truth-driven political websites.</a></li>          \n        </ul>\n</div>\n      <!--/ .widget-container-->\n\n<div align="center"><a href="http://uselections.com/go/BulletproofHome" target="_blank"><img src="https://uselections.com/images/affiliate/bulletproofhome_300x250_3.jpg" border="0" /></a></div>\n\n<br /><br />\n<!--<div align="center"><a title="bulletproof home text" href="http://uselections.com/go/BulletproofHome" target="_blank"><img src="https://uselections.com/images/affiliate/bulletproof-home-text.png" border="0" style="border: 0;" /></a></div><br /><br />-->\n           \n      <!--/ .widget-container-->\n<div class="widget-container eventsListWidget">\n        <h3 class="widget-title">Calendar Of Events</h3>\n        <ul>\n          <li><a href="https://uselections.com/calendar-us-elections.shtml">General Election - Click here for more info</a>\n          <span class="widget-date">November 7, 2017</span> </li>\n          <li><a href="https://uselections.com/calendar-us-elections.shtml">See More Events...</a> </li>\n        </ul>\n</div>\n      <!--/ .widget-container-->\n\n<div align="center"><a href="http://uselections.com/go/PatriotPrivacy" target="_blank"><img src="https://uselections.com/images/affiliate/patriotprivacy300w1.jpg" border="0" /></a></div>\n<br /><br />        \n<!--<div align="center"><a href="http://uselections.com/go/MyFamilySurvival" target="_blank"><img src="https://uselections.com/images/affiliate/familysurvival_300_250-3.jpg" border="0" /></a></div><br /><br />-->\n  \n      <!--/ .widget-container-->\n      <div class="widget-container widget_categories">\n        <h3 class="widget-title">Frequently Asked Questions</h3>\n        <ul>\n          <li><a href="https://uselections.com/QandA/index.shtml">How Do I\n              Register To Vote?</a></li>\n          <li><a href="https://uselections.com/QandA/index.shtml">I Don\'t\n              Know If I\'m Already Registered To Vote. How Do I Find Out?</a></li>\n          <li><a href="https://uselections.com/QandA/index.shtml">I\'ve Moved.\n              Do I Need To Re-Register To Vote?</a></li>\n          <li><a href="https://uselections.com/faq_voter_reg.htm">What Are My\n              State\'s Voter Laws &amp; Registration Deadlines?</a></li>\n          <li><a href="https://uselections.com/QandA/index.shtml">Where Do I\n              Go To Vote? (Polling Places)</a></li>\n          <li><a href="https://uselections.com/QandA/index.shtml">What Do I\n              Need To Bring With Me When I Vote?</a></li>\n          <li><a href="https://uselections.com/QandA/index.shtml">How Do I\n              Vote Absentee?</a></li>\n          <li><a href="https://uselections.com/QandA/index.shtml">What\n              District Do I Live In?</a></li>\n          <li><a href="https://uselections.com/QandA/contact-elected-representatives.shtml">How\n              Do I Contact My Elected Officials &amp; Politicans To Make My\n              Voice Heard?</a></li>\n          <li><a href="https://uselections.com/QandA/index.shtml">How Has My\n              Elected Official Voted On Every Bill &amp; Issue While In Office?</a></li>\n          <li><a href="https://uselections.com/QandA/index.shtml">Is My\n              Elected Offical Telling The Truth OR Full Of Crap?</a></li>\n          <li><a href="https://uselections.com/election_divisions.htm">What\n              Is My State\'s Election Info Website?</a></li>\n          <li><a href="https://uselections.com/QandA/primary-caucus-convention.shtml">What\'s\n              The Difference Between a Primary, Caucus &amp; Convention?</a></li>\n          <li><a href="https://uselections.com/QandA/primary-caucus-convention.shtml">How\n              Do I Vote Or Participate in a Primary Or Caucus?</a></li>\n          <li><a href="https://uselections.com/ideology/index.shtml">What Is\n              My Political Ideology? How do I figure it out?</a></li>\n        </ul>\n      </div>\n      <!--/ .widget-container-->\n<div>\n\n<!-- <div align="center"><a title="blackout usa" href="http://uselections.com/go/BlackoutUSA" target="_blank"><img src="https://uselections.com/images/affiliate/blackoutusa-text.png" border="0" style="border: 0;" /></a></div><br /><br /> -->\n\n<!-- <div align="center"><a href="https://uselections.com/join.php"><img src="https://uselections.com/images/Join-USE-300w.png" border="0" /></a></div><br /> -->\n    </aside>\n    <!--/ #sidebar-->\n    <!-- - - - - - - - - - - - - end Sidebar - - - - - - - - - - - - - - - - -->\n    <!--ZOOMRESTART-->\n\t\t\n\n\t\t\n\t\t<!--/ .bottomad -->\n\t\t\n\t\t\n\t</section><!--/.container -->\n    \n                <section class="container sbr clearfix">\n<table width="100%" align="center">\n<tr>\n<td width="100%" align="center">\n<div align="center" style="min-width:150px; max-width:500px;">\n<script>\n  (function() {\n    var cx = \'004503200095547316544:ibmdqaxbb0k\';\n    var gcse = document.createElement(\'script\');\n    gcse.type = \'text/javascript\';\n    gcse.async = true;\n    gcse.src = \'https://cse.google.com/cse.js?cx=\' + cx;\n    var s = document.getElementsByTagName(\'script\')[0];\n    s.parentNode.insertBefore(gcse, s);\n  })();\n</script>\n<gcse:searchbox-only></gcse:searchbox-only>\n  </div>\n</td>\n</tr>\n</table>\n</section>\n\t\t\n\t<!-- - - - - - - - - - - - - end Container - - - - - - - - - - - - - - - - -->\t\n\t\n<!--ZOOMSTOP-->\n\t<!-- - - - - - - - - - - - - - - Footer - - - - - - - - - - - - - - - - -->\t\n\t\n\t<footer id="footer" class="container clearfix">\n\t\t\n\t\t<div class="one-fourth">\n\t\t\t\n\t\t\t<div class="widget-container widget_text">\n\t\t\t\t\n\t\t\t\t<h3 class="widget-title">About Jeff Cohen, Founder</h3>\n\t\t\t\t\n\t\t\t\t<div class="textwidget">\n\t\t\t\t\t\n\t\t\t\t\t<p align="center"><img src="https://uselections.com/images/jc-pic.png" width="112" height="119" align="center" /></p>\n                    <p>I&nbsp;am a <u>registered Independent</u>.<br /><br />\n\t\t\t\t    Founded in 1999, my goal is to present ALL Americans with the necessary information vital to making smart, well-informed decisions. Let\'s elect representatives that have OUR best interests at heart.<br />\n\t\t\t\t\t</p>\t\n\t\t\t\t\t\n\t\t\t\t</div><!--/ .textwidget-->\n\t\t\t\t\n\t\t\t</div><!--/ .widget-container-->\n\t\t\t\n\t\t</div><!--/ .one-fourth-->\n\t\t\n\t\t<div class="one-fourth">\n\t\t\t\n\t\t\t<div class="widget-container widget_nav_menu">\n\t\t\t\t\n\t\t\t\t<h3 class="widget-title">Main Menu</h3>\n\n\t\t\t\t<div class="menu-custom_menu-container">\n\t\t\t\t\t\n\t\t\t\t\t<ul class="menu" id="menu-custom_menu">\n\n\t\t\t\t\t\t<li><a href="https://uselections.com">Home</a></li>\n\t\t\t\t\t\t<li><a href="https://uselections.com">News & Headlines</a></li>\n\t\t\t\t\t\t<li><a href="https://uselections.com/calendar-us-elections.shtml">Election Calendar</a></li>\n\t\t\t\t\t\t<li><a href="https://uselections.com/pres.htm">President</a></li>\n\t\t\t\t\t\t<li><a href="https://uselections.com/uselections/">50 States</a></li>\n                        <li><a href="https://uselections.com/us-congressional-district-map.shtml">Find Your District</a></li>\n                        <li><a href="https://uselections.com/usa_localities/">Find Your Home Town</a></li>\n                        <li><a href="https://uselections.com/parties.htm">National Parties</a></li>\n                        \n\t\t\t\t\t\t\n\t\t\t\t\t</ul><!--/ .menu-->\t\t\n\t\t\t\t\n\t\t\t\t</div><!--/ .menu-custom_menu-container-->\n\t\t\t\t\n\t\t\t</div><!--/ .widget-container-->\n\t\t\t\n\t\t</div><!--/ .one-fourth-->\n\t\t\n\t\t<div class="one-fourth">\n\t\t\t\n\t\t\t<div class="widget-container widget_links">\n\t\t\t\t\n\t\t\t  <h3 class="widget-title">Main Menu</h3>\n\t\t\t\n\t\t\t\t<ul>\n                \n                    <li><a href="https://uselections.com/m/answers/home/">Answers / Q&amp;A</a></li>\n                    <li><a href="https://uselections.com/qanda.htm">Voting</a></li>\n                    <li><a href="https://uselections.com/m/sites/home/">Great Websites</a></li>\n                    <li><a href="https://uselections.com/us-government-publications.shtml">Free Govt Pubs</a></li>\n                    <li><a href="https://uselections.com/submissions/SuggestionBox/ideas.php" onclick="window.open(\'https://uselections.com/submissions/SuggestionBox/ideas.php\',\'popup\',\'width=550,height=350,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0\'); return false"><strong>Suggestion Box</strong></a></li>\n                    <li><a href="https://uselections.com/submissions/Submissions/politicians.php" onclick="window.open(\'https://uselections.com/submissions/Submissions/politicians.php\',\'popup\',\'width=550,height=550,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0\'); return false"><strong>Submit Candidate Info</strong></a></li>\n                    <li><a href="https://uselections.com/m/google_search/"><strong>Search</strong></a></li>\n                    <li><a href="https://uselections.com/contact.php"><strong>Contact Me</strong></a></li>\n\n\t\t\t\t</ul>\n\t\t\t\t\n\t\t\t</div><!--/ .widget-container-->\n\t\t\t\n\t\t</div><!--/ .one-fourth-->\n\t\t\n\t\t<div class="one-fourth last">\n\t\t\t\n\t\t\t<div class="widget-container widget_links">\n\t\t\t\n\t\t\t\t<h3 class="widget-title">Hot Links</h3>\n\n\t\t\t\t<ul>\n\n\t\t\t\t\t<li><a href="https://uselections.com/m/sites/view/Democracy-io-Contact-your-Members-of-Congress">Democracy.io</a><br />Contact members of congress.</li>\n                    <li><a href="https://uselections.com/m/sites/view/Contact-or-Follow-Your-US-Representatives-RepsContacts-com">RepsContacts.com</a><br />Contact or follow your US Representatives.</li>\n                    <li><a href="https://uselections.com/m/sites/view/5Calls-org-Make-Your-Voice-Heard">5calls.org</a><br />Make your voice heard.</li>\n                    <li><a href="https://uselections.com/m/sites/view/Town-Hall-Project-Find-a-Town-Hall-Near-You">TownHallProject</a><br />Find a town hall near you.</li>\n                    <li><a href="https://uselections.com/m/sites/view/OnTheIssues">OnTheIssues.Org</a><br />How every politician stands on every issue. The truth.</li>\n\t\t\t\t\t<li><a href="https://petitions.whitehouse.gov/">We The People</a><br />Petition the White House on important issues to you.</li>\n                    <li><a href="https://uselections.com/m/sites/home/">More Great Sites...</a><br />Click here.</li>\n\n\t\t\t\t</ul>\t\t\t\t\n\t\t\t\t\n\t\t\t</div><!--/ .widget-container-->\n\t\t\t\n\t\t</div><!--/ .one-fourth .last-->\n\t\t\n\t\t<div class="clear"></div>\n\t\t\n\t\t<ul class="copyright">\n\t\t\t\n\t\t\t<li>Copyright @ 1999-2017</li>\n\t\t\t<li><a href="https://launch3.com">Launch 3, LLC</a></li>\n\t\t\t<li>All rights reserved</li>\n\t\t\t<li>11:11</li>\n\t\t\t\n\t\t</ul>\n\t\t<!--/ .copyright-->\n\t\n\t</footer><!--/ #footer-->\n\t\n\t<!-- - - - - - - - - - - - - - - end Footer - - - - - - - - - - - - - - - - -->\t\n    \n\n<!-- Quantcast Tag -->\n<script type="text/javascript">\nvar _qevents = _qevents || [];\n\n(function() {\nvar elem = document.createElement(\'script\');\nelem.src = (document.location.protocol == "https:" ? "https://secure" : "http://edge") + ".quantserve.com/quant.js";\nelem.async = true;\nelem.type = "text/javascript";\nvar scpt = document.getElementsByTagName(\'script\')[0];\nscpt.parentNode.insertBefore(elem, scpt);\n})();\n\n_qevents.push({\nqacct:"p-73p7xrPPlmFnI"\n});\n</script>\n\n<noscript>\n<div style="display:none;">\n<img src="//pixel.quantserve.com/pixel/p-73p7xrPPlmFnI.gif" border="0" height="1" width="1" alt="Quantcast"/>\n</div>\n</noscript>\n<!-- End Quantcast tag -->\n<!--ZOOMRESTART-->\t\n\t\n</div><!--/ .wrap-->\n\t\n\n<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>\t\n<script>window.jQuery || document.write(\'<script src="//uselections.com/js/jquery-1.7.1.min.js"><\\/script>\')</script>\n<!--[if lt IE 9]>\n\t<script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE8.js"></script>\n\t<script src="js/ie.js"></script>\n<![endif]-->\n<script src="//uselections.com/js/custom.js"></script>\n</body>\n</html>\n\n'

Parse the site's contents

Again, the same as above, but with a new regex on a new page.

In [9]:
res_2 = re.search(b'<a href=.*>(.*)\S(last update)',p_2)
output_2 = res_2.group(1).decode('UTF-8')
print(output_2)
October 21, 2017 

Combine Stuff

Now we're going to take the values you found above and do something with them. The new thing you'll be seeing in this code is the If statement. In Python, if you type if [some evaluation]: then the code directly below that statement and indented once will run only if that evaluation is true. For example:

In [10]:
# The If statment below says: If the variables res_1 and res_2 actually exist, do what follows.
if output_1 and res_2: 
    # Make sure res_1 is in a format we can read (that's the "decode" part)
    # output_1 equal to regex match on page one.
    output_1 = p_1
    # Do the same thing as above but for res_2
    output_2 = res_2.group(1).decode('UTF-8')
    # Combine titles. Then store the value in the variable named "titles."
    #titles = output_1 + " AND " + output_2

Post to Twitter and Save to Google

In [12]:
if p_1 and res_2: 
    # Again, the above tells the program to continue with what follows only if res_1 and res_2 exist
    
    if ((worksheet.row_values(worksheet.row_count)[1] != output_1) or (worksheet.row_values(worksheet.row_count)[2] != output_2)):
        # The above If statment, says to continue only if the old sheet vales and 
        # the new pulled values are not equal (!=) to eachother. 
        
        if ((worksheet.row_values(worksheet.row_count)[1]) != output_1):
            # The above If statment says to continue only if the first value is 
            # different from the last version stored in the sheet.
                            
            # Go ahead and tweet out the update. Here you need to know about a Twitter API limitation.
            # Twitter will not Tweet the same tweet a second time if it is too close to the first instance.
            # In such cases, it will throw an error. The `try:` and `except TwitterError:` constructions are
            # similar to If statements. However, they will try the first block of code first, and only try 
            # the second block if it runs into a Twitter error. Here, the second try tweaks the language
            # just enough that it isn't a duplicate Tweet.
            try:
                # Post to Twitter.
                #print ('P1 Title is %s'%(output_1))
                status = api.PostUpdate('The contents of the link changed: https://goo.gl/axTtaJ')
                print(status.text)
            except TwitterError:
                # Post to Twitter.
                #print ('P1 Title: %s'%(output_1))
                status = api.PostUpdate('Again, the contents have changed: https://goo.gl/axTtaJ')
                print(status.text)

        # What follows is effctivly the above but for the second value.         
        if (((worksheet.row_values(worksheet.row_count)[2]) != output_2)):

            try:
                #print ('P2 Title is %s'%(output_2))
                status = api.PostUpdate('https://goo.gl/LNguu7 was updated on %s'%(output_2))
                print(status.text)
            except TwitterError:
                #print ('P2 Title: %s'%(output_2))
                status = api.PostUpdate('Again, https://goo.gl/LNguu7 was updated on %s'%(output_2))
                print(status.text)
                                
        worksheet.append_row([now,output_1,output_2])
Again, the contents have changed: https://t.co/3gp6a7B9dR
Again, https://t.co/XdjUohM5IR was updated on October 21, 2017
In [ ]:
 
In [ ]: