Adapted from the notebook found at How to Build a Law Bot

My twitter bot will take a quote from Notable Law Quotes. Notable Law Quotes lists quotes in order of "most liked" to "least liked." As the most liked quote changes, my bot will tweet the new most liked quote. My regular expression should take the quote, the author, and where the quote appears--such as in which book it appears--and string them together and save it into a google drive spread sheet I created. After that, it should tweet the quote in a single tweet to this twitter page. It could become a problem should a quote be more than 140 characters. I am not sure what will happen in that case. To ensure my bot complies with the CFAA, I added "robots.txt" to the url to see if bots had permission. Notable Law Quotes doesn't have a robots.txt page. I then searched through its privacy page. It appears the website wants you to share the quotes because it describes no prohibition, and does not have a terms of service page that I can find.

In [16]:
# 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 [17]:
# Set the URL you want to scrape.
url_1 = "http://www.notable-quotes.com/l/law_quotes.html"

# If you want to scrape data from multiple pages, you can, 
# just replicate the above and below but change url_1 to url_2 et al.
In [18]:
# Load the module for accessing Google Sheets.
import gspread
# Load the module needed for securely communicating with Google Sheets.
from oauth2client.service_account import ServiceAccountCredentials
# The scope for your access credentials
scope = ['https://spreadsheets.google.com/feeds']

# Your spreadsheet's ID
document_key = "1-teq-x4A1ITVOcQQhZEysoDziNqdl2ZRwHGiipJHDUk" 
#              ^^^^^^^^^^^ SWAP OUT FOR YOUR DOCUMENT ID/KEY
# Your Google project's .json key
credentials = ServiceAccountCredentials.from_json_keyfile_name('../../../../../Twitterbot-f07c559e66ba.json', scope)
#                                                                              ^^^^^^^^ SWAP OUT FOR YOUR JSON KEY
# 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)

#########################################
#
#  NOTE: The name of the sheet you are 
#  trying to access should be in the 
#  parenthetical below (e.g., Data). By
#  Default this is probably "Sheet1".
#
#########################################
worksheet = wks.worksheet("Sheet1")

# Count the number of rows in your Sheet &
# resize to remove blank rows.
worksheet.resize(worksheet.row_count)
In [19]:
# Import the relevant Twitter libraries so you can use Twitter.
import twitter
from twitter import TwitterError

# create the following four text files and add them to the same diretctry as you 
# Google API key. In each file add the appropriate value found when retrieving your 
# Twitter credentials

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()

# Set you Twitter API credentials.
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 [20]:
p_1 = urllib.request.build_opener(urllib.request.HTTPCookieProcessor).open(url_1).read()
print(p_1)
b'<!DOCTYPE html>\r\n<html lang="en">\r\n  <head>\r\n    <meta charset="utf-8">\r\n    <meta http-equiv="X-UA-Compatible" content="IE=edge">\r\n    <meta name="viewport" content="width=device-width, initial-scale=1">\r\n    <title>Law Quotes</title>\r\n\t<meta name="description" content="A collection of quotes about law.">\r\n\t<link rel="canonical" href="http://www.notable-quotes.com/l/law_quotes.html">\r\n\t<link rel="next" href="http://www.notable-quotes.com/l/law_quotes_ii.html">\r\n    <!-- Bootstrap -->\r\n    <link href="http://notable-quotes.com/css/bootstrap.css" rel="stylesheet">\r\n\t<link href="http://notable-quotes.com/css/style.css" rel="stylesheet">\r\n\r\n    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->\r\n    <!-- WARNING: Respond.js doesn\'t work if you view the page via file:// -->\r\n    <!--[if lt IE 9]>\r\n      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>\r\n      <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>\r\n    <![endif]-->\r\n<style>\r\n\t.col-md-9 {\r\n\tmargin-left: 20px;\r\n\tmargin-right: 20px;\r\n\tpadding: 0px 20px 0px 20px;\r\n\t}\r\n\t.sky.col-md-2 {\r\n\tbackground-color: #bdcaae;\r\n\t}\r\n\t.body.row {\r\n\tbackground-color: #e7f4d8;\r\n\tborder-radius: 10px;\r\n\tmargin-top: 20px;\r\n\tpadding-bottom: 10px;\r\n\tpadding-left: 20px;\r\n\tpadding-right: 20px;\r\n\t}\r\n\th2 {\r\n\ttext-align: center;\r\n\t}\r\n\t.navbar-inverse .navbar-brand {\r\n\tpadding: 7px 10px;\r\n\t}\r\n\tp.subtit {\r\n\ttext-align: center;\r\n\tfont-weight: bold;\r\n\t}\r\n\tp.quotation {\r\n\tcolor: #383838;\r\n\tfont-family: georgia,sans-serif;\r\n\tfont-size: 150%;\r\n\ttext-align: left;\r\n\t}\r\n\tp.attribution {\r\n\tcolor: #567843;\r\n\tfont-size: 125%;\r\n\ttext-align: right;\r\n\t}\r\n\tp.lkcounter {\r\n\tcolor: #567843;\r\n\ttext-align: left;\r\n\tdisplay: inline-block;\r\n\t}\r\n\tp.lnktags {\r\n\tcolor: #567843;\r\n\tfont-size: 75%;\r\n\ttext-align: left;\r\n\t}\r\n\tp.followus {\r\n\tcolor: #ffffff;\r\n\ttext-align: left;\r\n\tfont-weight: bold;\r\n\tmargin-right: 15px;\r\n\tmargin-top: 15px;\r\n\t}\r\n\tdiv.lkbt {\r\n\ttext-align: left;\r\n\tdisplay: inline-block;\r\n\tmargin-left: 10px;\r\n\t}\r\n\tdiv.picqt {\r\n\ttext-align: center;\r\n\tmargin-bottom: 10px;\r\n\t}\r\n\timg {\r\n\tmax-width: 100%;\r\n\t}\r\n</style>\r\n\r\n<script type="text/javascript">\r\nfunction saveScrollPositions(theForm) {\r\nif(theForm) {\r\nvar scrolly = typeof window.pageYOffset != \'undefined\' ? window.pageYOffset : document.documentElement.scrollTop;\r\nvar scrollx = typeof window.pageXOffset != \'undefined\' ? window.pageXOffset : document.documentElement.scrollLeft;\r\ntheForm.scrollx.value = scrollx;\r\ntheForm.scrolly.value = scrolly;\r\n}\r\n}\r\n</script>\r\n  </head>\r\n  <body>\r\n\t<nav class="navbar navbar-inverse navbar-static-top" role="navigation">\r\n  <div class="container-fluid">\r\n    <!-- Brand and toggle get grouped for better mobile display -->\r\n    <div class="navbar-header">\r\n      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">\r\n        <span class="sr-only">Toggle navigation</span>\r\n        <span class="icon-bar"></span>\r\n        <span class="icon-bar"></span>\r\n        <span class="icon-bar"></span>\r\n      </button>\r\n      <a class="navbar-brand" href="../index.html"><img src="../images/nqlogo2.png"></a>\r\n    </div>\r\n\r\n    <!-- Collect the nav links, forms, and other content for toggling -->\r\n    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">\r\n      <ul class="nav navbar-nav">\r\n        <li class="dropdown">\r\n          <a href="../subject_index.html" class="active dropdown-toggle" data-toggle="dropdown">Browse quotes by subject<b class="caret"></b></a>\r\n          <ul class="dropdown-menu">\r\n            <li><a href="../a/subject_index.html">A</a></li>\r\n            <li><a href="../b/subject_index.html">B</a></li>\r\n\t\t\t<li><a href="../c/subject_index.html">C</a></li>\r\n\t\t\t<li><a href="../d/subject_index.html">D</a></li>\r\n\t\t\t<li><a href="../e/subject_index.html">E</a></li>\r\n\t\t\t<li><a href="../f/subject_index.html">F</a></li>\r\n\t\t\t<li><a href="../g/subject_index.html">G</a></li>\r\n\t\t\t<li><a href="../h/subject_index.html">H</a></li>\r\n\t\t\t<li><a href="../i/subject_index.html">I</a></li>\r\n\t\t\t<li><a href="../j/subject_index.html">J</a></li>\r\n\t\t\t<li><a href="../k/subject_index.html">K</a></li>\r\n\t\t\t<li><a href="../l/subject_index.html">L</a></li>\r\n\t\t\t<li><a href="../m/subject_index.html">M</a></li>\r\n\t\t\t<li><a href="../n/subject_index.html">N</a></li>\r\n\t\t\t<li><a href="../o/subject_index.html">O</a></li>\r\n\t\t\t<li><a href="../p/subject_index.html">P</a></li>\r\n\t\t\t<li><a href="../q/subject_index.html">Q</a></li>\r\n\t\t\t<li><a href="../r/subject_index.html">R</a></li>\r\n\t\t\t<li><a href="../s/subject_index.html">S</a></li>\r\n\t\t\t<li><a href="../t/subject_index.html">T</a></li>\r\n\t\t\t<li><a href="../u/subject_index.html">U</a></li>\r\n\t\t\t<li><a href="../v/subject_index.html">V</a></li>\r\n\t\t\t<li><a href="../w/subject_index.html">W</a></li>\r\n\t\t\t<li><a href="../x/subject_index.html">X</a></li>\r\n\t\t\t<li><a href="../y/subject_index.html">Y</a></li>\r\n\t\t\t<li><a href="../z/subject_index.html">Z</a></li>\r\n          </ul>\r\n        </li>\r\n\t\t<li class="dropdown">\r\n          <a href="../author_index.html" class="active dropdown-toggle" data-toggle="dropdown">Browse quotes by author<b class="caret"></b></a>\r\n          <ul class="dropdown-menu">\r\n            <li><a href="../a/">A</a></li>\r\n            <li><a href="../b/">B</a></li>\r\n\t\t\t<li><a href="../c/">C</a></li>\r\n\t\t\t<li><a href="../d/">D</a></li>\r\n\t\t\t<li><a href="../e/">E</a></li>\r\n\t\t\t<li><a href="../f/">F</a></li>\r\n\t\t\t<li><a href="../g/">G</a></li>\r\n\t\t\t<li><a href="../h/">H</a></li>\r\n\t\t\t<li><a href="../i/">I</a></li>\r\n\t\t\t<li><a href="../j/">J</a></li>\r\n\t\t\t<li><a href="../k/">K</a></li>\r\n\t\t\t<li><a href="../l/">L</a></li>\r\n\t\t\t<li><a href="../m/">M</a></li>\r\n\t\t\t<li><a href="../n/">N</a></li>\r\n\t\t\t<li><a href="../o/">O</a></li>\r\n\t\t\t<li><a href="../p/">P</a></li>\r\n\t\t\t<li><a href="../q/">Q</a></li>\r\n\t\t\t<li><a href="../r/">R</a></li>\r\n\t\t\t<li><a href="../s/">S</a></li>\r\n\t\t\t<li><a href="../t/">T</a></li>\r\n\t\t\t<li><a href="../u/">U</a></li>\r\n\t\t\t<li><a href="../v/">V</a></li>\r\n\t\t\t<li><a href="../w/">W</a></li>\r\n\t\t\t<li><a href="../x/">X</a></li>\r\n\t\t\t<li><a href="../y/">Y</a></li>\r\n\t\t\t<li><a href="../z/">Z</a></li>\r\n          </ul>\r\n        </li>\r\n      </ul>\r\n      <form class="navbar-form navbar-left" method=GET action="http://www.google.com/search" role="search">\r\n        <div class="form-group">\r\n\t\t<input type=hidden name=ie value=UTF-8>\r\n\t\t<input type=hidden name=oe value=UTF-8>\r\n          <input type="text" class="form-control" name=q size=20 maxlength=255 placeholder="Search for Quotes">\r\n\t\t  <input type=hidden name=domains value="notable-quotes.com">\r\n\t\t  <input type=hidden name=sitesearch value="notable-quotes.com">\r\n        </div>\r\n        <button type="submit" class="btn btn-default">Submit</button>\r\n      </form>\t  \r\n      <ul class="nav navbar-nav navbar-right">\r\n        <li><p class="followus">Follow us!</li>\r\n\t\t<li><a class="navbar-brand" href="https://www.facebook.com/QuotesNotable"><img src="../images/facebook.png" onmouseover="this.src=\'../images/facebook_bw.png\'" onmouseout="this.src=\'../images/facebook.png\'" hspace="1" vspace="1"></a></li>\r\n\t\t<li><a class="navbar-brand" href="https://twitter.com/QuotesNotable"><img src="../images/twitter.png" onmouseover="this.src=\'../images/twitter_bw.png\'" onmouseout="this.src=\'../images/twitter.png\'" hspace="1" vspace="1"></a></li>\r\n\t\t<li><a class="navbar-brand" href="https://plus.google.com/+Notablequotessite"><img src="../images/googleplus.png" onmouseover="this.src=\'../images/googleplus_bw.png\'" onmouseout="this.src=\'../images/googleplus.png\'" hspace="1" vspace="1" style="margin-right:10px"></a></li></p>\r\n      </ul>\r\n    </div><!-- /.navbar-collapse -->\r\n  </div><!-- /.container-fluid -->\r\n</nav>\r\n\t<div class="container">\r\n\t\t<div class="row">\r\n\t\t\t<div class="col-md-12">\r\n\t\t\t<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>\r\n\t<!-- Notable Quotes - Responsive -->\r\n\t<ins class="adsbygoogle"\r\n\tstyle="display:block"\r\n\tdata-ad-client="ca-pub-4793167219639586"\r\n\tdata-ad-slot="2545087820"\r\n\tdata-ad-format="auto"></ins>\r\n\t<script>\r\n\t(adsbygoogle = window.adsbygoogle || []).push({});\r\n\t</script>\t\t\t</div>\r\n\t\t</div>\r\n\t\t<div class="row">\r\n\t\t\t<div class="col-md-9">\r\n\t\t\t<div class="row body">\r\n\t\t\t\t<h2>LAW QUOTES</h2>\r\n\t\t\t\t<p class="subtit">quotations about law</p>\r\n\t\t\t\t<div class="picqt"><img src="law_quote.jpg" alt="Law quote"></div>\r\n\t\t\t\t\r\n\t\t\t\t<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">\r\n\r\n<ul class="pagination"><li class="disabled"><span>&laquo;</span></li><li class="active"><span>1</span></li><li><a href="law_quotes_ii.html">2</a></li><li><a href="law_quotes_iii.html">3</a></li><li><a href="law_quotes_iv.html">4</a></li><li><a href="law_quotes_v.html">5</a></li><li><a href="law_quotes_vi.html">6</a></li><li><a href="law_quotes_vii.html">7</a></li><li><a href="law_quotes_viii.html">8</a></li><li><a href="law_quotes_ix.html">9</a></li><li><a href="law_quotes_ix.html">&raquo;</a></li></ul><p class="quotation">Laws grind the poor, and rich men rule the law.</p><p class="attribution">OLIVER GOLDSMITH, <em>The Traveller</em></p><p class="lkcounter"><small>41 likes </small><div class="lkbt"><form method="post" onsubmit="return saveScrollPositions(this);"><button type="submit" class="btn btn-primary btn-sm">like</button><input type="hidden" name="id" value="12"><input type="hidden" name="likes" value="41"><input type="hidden" name="scrollx" id="scrollx" value="0" /><input type="hidden" name="scrolly" id="scrolly" value="0" /></form></p></div><p class="lnktags">Tags: <a href="http://www.notable-quotes.com/g/goldsmith_oliver.html">Oliver Goldsmith</a></p><hr><p class="quotation">Law is order, and good law is good order.</p><p class="attribution">ARISTOTLE, <em>Politics</em></p><p class="lkcounter"><small>26 likes </small><div class="lkbt"><form method="post" onsubmit="return saveScrollPositions(this);"><button type="submit" class="btn btn-primary btn-sm">like</button><input type="hidden" name="id" value="30"><input type="hidden" name="likes" value="26"><input type="hidden" name="scrollx" id="scrollx" value="0" /><input type="hidden" name="scrolly" id="scrolly" value="0" /></form></p></div><p class="lnktags">Tags: <a href="http://www.notable-quotes.com/a/aristotle_quotes.html">Aristotle</a></p><hr><p class="quotation">People are more afraid of the laws of Man than of God, because their punishment seems to be nearest.</p><p class="attribution">WILLIAM PENN, <em>Some Fruits of Solitude</em></p><p class="lkcounter"><small>26 likes </small><div class="lkbt"><form method="post" onsubmit="return saveScrollPositions(this);"><button type="submit" class="btn btn-primary btn-sm">like</button><input type="hidden" name="id" value="60"><input type="hidden" name="likes" value="26"><input type="hidden" name="scrollx" id="scrollx" value="0" /><input type="hidden" name="scrolly" id="scrolly" value="0" /></form></p></div><p class="lnktags">Tags: <a href="http://www.notable-quotes.com/p/penn_william.html">William Penn</a></p><hr><p class="quotation">Laws are like cobwebs, which may catch small flies, but let wasps and hornets break through.</p><p class="attribution">JONATHAN SWIFT, <em>A Critical Essay upon the Faculties of the Mind</em></p><p class="lkcounter"><small>18 likes </small><div class="lkbt"><form method="post" onsubmit="return saveScrollPositions(this);"><button type="submit" class="btn btn-primary btn-sm">like</button><input type="hidden" name="id" value="8"><input type="hidden" name="likes" value="18"><input type="hidden" name="scrollx" id="scrollx" value="0" /><input type="hidden" name="scrolly" id="scrolly" value="0" /></form></p></div><p class="lnktags">Tags: <a href="http://www.notable-quotes.com/s/swift_jonathan.html">Jonathan Swift</a></p><hr><p class="quotation">There is but one law for all, namely, that law which governs all law, the law of our Creator, the law of humanity, justice, equity -- the law of nature and of nations.</p><p class="attribution">EDMUND BURKE, speech on Impeachment of Warren Hastings, May 28, 1794</p><p class="lkcounter"><small>16 likes </small><div class="lkbt"><form method="post" onsubmit="return saveScrollPositions(this);"><button type="submit" class="btn btn-primary btn-sm">like</button><input type="hidden" name="id" value="17"><input type="hidden" name="likes" value="16"><input type="hidden" name="scrollx" id="scrollx" value="0" /><input type="hidden" name="scrolly" id="scrolly" value="0" /></form></p></div><hr><p class="quotation">The law is the public conscience.</p><p class="attribution">THOMAS HOBBES, <em>Leviathan</em></p><p class="lkcounter"><small>14 likes </small><div class="lkbt"><form method="post" onsubmit="return saveScrollPositions(this);"><button type="submit" class="btn btn-primary btn-sm">like</button><input type="hidden" name="id" value="3"><input type="hidden" name="likes" value="14"><input type="hidden" name="scrollx" id="scrollx" value="0" /><input type="hidden" name="scrolly" id="scrolly" value="0" /></form></p></div><p class="lnktags">Tags: <a href="http://www.notable-quotes.com/h/hobbes_thomas.html">Thomas Hobbes</a></p><hr><p class="quotation">The law was made for one thing alone, for the exploitation of those who don\'t understand it.</p><p class="attribution">BERTOLT BRECHT, <em>The Threepenny Opera</em></p><p class="lkcounter"><small>12 likes </small><div class="lkbt"><form method="post" onsubmit="return saveScrollPositions(this);"><button type="submit" class="btn btn-primary btn-sm">like</button><input type="hidden" name="id" value="9"><input type="hidden" name="likes" value="12"><input type="hidden" name="scrollx" id="scrollx" value="0" /><input type="hidden" name="scrolly" id="scrolly" value="0" /></form></p></div><p class="lnktags">Tags: <a href="http://www.notable-quotes.com/b/brecht_bertolt.html">Bertolt Brecht</a></p><hr><p class="quotation">Without law men are beasts.</p><p class="attribution">MAXWELL ANDERSON, <em>Winterset</em></p><p class="lkcounter"><small>11 likes </small><div class="lkbt"><form method="post" onsubmit="return saveScrollPositions(this);"><button type="submit" class="btn btn-primary btn-sm">like</button><input type="hidden" name="id" value="33"><input type="hidden" name="likes" value="11"><input type="hidden" name="scrollx" id="scrollx" value="0" /><input type="hidden" name="scrolly" id="scrolly" value="0" /></form></p></div><p class="lnktags">Tags: <a href="http://www.notable-quotes.com/a/anderson_maxwell.html">Maxwell Anderson</a></p><hr><p class="quotation">A law is valuable, not because it is a law, but because there is right in it.</p><p class="attribution">HENRY WARD BEECHER, <em>Life Thoughts</em></p><p class="lkcounter"><small>11 likes </small><div class="lkbt"><form method="post" onsubmit="return saveScrollPositions(this);"><button type="submit" class="btn btn-primary btn-sm">like</button><input type="hidden" name="id" value="55"><input type="hidden" name="likes" value="11"><input type="hidden" name="scrollx" id="scrollx" value="0" /><input type="hidden" name="scrolly" id="scrolly" value="0" /></form></p></div><hr><p class="quotation">No organic law can ever be framed with a provision specifically applicable to every question which may occur in practical administration. No foresight can anticipate nor any document of reasonable length contain express provisions for all possible questions.</p><p class="attribution">ABRAHAM LINCOLN, First Inaugural Address, Mar. 4, 1861</p><p class="lkcounter"><small>10 likes </small><div class="lkbt"><form method="post" onsubmit="return saveScrollPositions(this);"><button type="submit" class="btn btn-primary btn-sm">like</button><input type="hidden" name="id" value="24"><input type="hidden" name="likes" value="10"><input type="hidden" name="scrollx" id="scrollx" value="0" /><input type="hidden" name="scrolly" id="scrolly" value="0" /></form></p></div><p class="lnktags">Tags: <a href="http://www.notable-quotes.com/l/lincoln_abraham.html">Abraham Lincoln</a></p><hr><p class="quotation">Lawyers are the only persons in whom ignorance of the law is not punished.</p><p class="attribution">JEREMY BENTHAM, <em>The Canadian Bar Journal</em>, Jun. 1966</p><p class="lkcounter"><small>9 likes </small><div class="lkbt"><form method="post" onsubmit="return saveScrollPositions(this);"><button type="submit" class="btn btn-primary btn-sm">like</button><input type="hidden" name="id" value="20"><input type="hidden" name="likes" value="9"><input type="hidden" name="scrollx" id="scrollx" value="0" /><input type="hidden" name="scrolly" id="scrolly" value="0" /></form></p></div><p class="lnktags">Tags: <a href="http://www.notable-quotes.com/b/bentham_jeremy.html">Jeremy Bentham</a></p><hr><p class="quotation">I am free, no matter what rules surround me. If I find them tolerable, I tolerate them; if I find them too obnoxious, I break them. I am free because I know that I alone am morally responsible for everything I do.</p><p class="attribution">ROBERT A. HEINLEIN, <em>The Moon Is a Harsh Mistress</em></p><p class="lkcounter"><small>9 likes </small><div class="lkbt"><form method="post" onsubmit="return saveScrollPositions(this);"><button type="submit" class="btn btn-primary btn-sm">like</button><input type="hidden" name="id" value="145"><input type="hidden" name="likes" value="9"><input type="hidden" name="scrollx" id="scrollx" value="0" /><input type="hidden" name="scrolly" id="scrolly" value="0" /></form></p></div><hr><p class="quotation">One with the law is a majority.</p><p class="attribution">CALVIN COOLIDGE, <em>New York Times</em>, Jul. 28, 1920</p><p class="lkcounter"><small>7 likes </small><div class="lkbt"><form method="post" onsubmit="return saveScrollPositions(this);"><button type="submit" class="btn btn-primary btn-sm">like</button><input type="hidden" name="id" value="11"><input type="hidden" name="likes" value="7"><input type="hidden" name="scrollx" id="scrollx" value="0" /><input type="hidden" name="scrolly" id="scrolly" value="0" /></form></p></div><hr><p class="quotation">Law without justice is a wound without a cure.</p><p class="attribution">WILLIAM SCOTT DOWNEY, <em>Proverbs</em></p><p class="lkcounter"><small>7 likes </small><div class="lkbt"><form method="post" onsubmit="return saveScrollPositions(this);"><button type="submit" class="btn btn-primary btn-sm">like</button><input type="hidden" name="id" value="44"><input type="hidden" name="likes" value="7"><input type="hidden" name="scrollx" id="scrollx" value="0" /><input type="hidden" name="scrolly" id="scrolly" value="0" /></form></p></div><p class="lnktags">Tags: <a href="http://www.notable-quotes.com/d/downey_william_scott.html">William Scott Downey</a></p><hr><p class="quotation">The precepts of the law may be comprehended under these three points: to live honestly, to hurt no man willfully, and to render every man his due carefully.</p><p class="attribution">ARISTOTLE, attributed, <em>Day\'s Collacon</em></p><p class="lkcounter"><small>7 likes </small><div class="lkbt"><form method="post" onsubmit="return saveScrollPositions(this);"><button type="submit" class="btn btn-primary btn-sm">like</button><input type="hidden" name="id" value="134"><input type="hidden" name="likes" value="7"><input type="hidden" name="scrollx" id="scrollx" value="0" /><input type="hidden" name="scrolly" id="scrolly" value="0" /></form></p></div><hr><p class="quotation">Law is an imperfect profession in which success can rarely be achieved without some sacrifice of principle. Thus all practicing lawyers -- and most others in the profession -- will necessarily be imperfect, especially in the eyes of young idealists. There is no perfect justice, just as there is no absolute in ethics. But there is perfect injustice, and we know it when we see it.</p><p class="attribution">ALAN DERSHOWITZ, <em>Letters to a Young Lawyer</em></p><p class="lkcounter"><small>6 likes </small><div class="lkbt"><form method="post" onsubmit="return saveScrollPositions(this);"><button type="submit" class="btn btn-primary btn-sm">like</button><input type="hidden" name="id" value="13"><input type="hidden" name="likes" value="6"><input type="hidden" name="scrollx" id="scrollx" value="0" /><input type="hidden" name="scrolly" id="scrolly" value="0" /></form></p></div><p class="lnktags">Tags: <a href="http://www.notable-quotes.com/d/dershowitz_alan.html">Alan Dershowitz</a></p><hr><p class="quotation">I don\'t go by what the law say. The law\'s liable to say anything. I go by if it\'s right or not. It don\'t matter what the law say. I take and look at it for myself.</p><p class="attribution">AUGUST WILSON, <em>The Piano Lesson</em></p><p class="lkcounter"><small>6 likes </small><div class="lkbt"><form method="post" onsubmit="return saveScrollPositions(this);"><button type="submit" class="btn btn-primary btn-sm">like</button><input type="hidden" name="id" value="14"><input type="hidden" name="likes" value="6"><input type="hidden" name="scrollx" id="scrollx" value="0" /><input type="hidden" name="scrolly" id="scrolly" value="0" /></form></p></div><p class="lnktags">Tags: <a href="http://www.notable-quotes.com/w/wilson_august.html">August Wilson</a></p><hr><p class="quotation">The law, in its majestic equality, forbids the rich as well as the poor to sleep under bridges, to beg in the streets, and to steal bread.</p><p class="attribution">ANATOLE FRANCE, <em>The Red Lily</em></p><p class="lkcounter"><small>5 likes </small><div class="lkbt"><form method="post" onsubmit="return saveScrollPositions(this);"><button type="submit" class="btn btn-primary btn-sm">like</button><input type="hidden" name="id" value="5"><input type="hidden" name="likes" value="5"><input type="hidden" name="scrollx" id="scrollx" value="0" /><input type="hidden" name="scrolly" id="scrolly" value="0" /></form></p></div><p class="lnktags">Tags: <a href="http://www.notable-quotes.com/f/france_anatole.html">Anatole France</a></p><hr><p class="quotation">Even when laws have been written down, they ought not always to remain unaltered.</p><p class="attribution">ARISTOTLE, <em>Politics</em></p><p class="lkcounter"><small>5 likes </small><div class="lkbt"><form method="post" onsubmit="return saveScrollPositions(this);"><button type="submit" class="btn btn-primary btn-sm">like</button><input type="hidden" name="id" value="76"><input type="hidden" name="likes" value="5"><input type="hidden" name="scrollx" id="scrollx" value="0" /><input type="hidden" name="scrolly" id="scrolly" value="0" /></form></p></div><p class="lnktags">Tags: <a href="http://www.notable-quotes.com/a/aristotle_quotes.html">Aristotle</a></p><hr><p class="quotation">No man-made law ever, no matter whether derived from the past or projected onto a distant, unforeseeable future, can or should ever be empowered to claim that it is greater than the Natural Law from which it stems and to which it must inevitably return in the eternal rhythm of creation and decline of all things natural.</p><p class="attribution">WILHELM REICH, response to FDA complaint, Feb. 22, 1954</p><p class="lkcounter"><small>5 likes </small><div class="lkbt"><form method="post" onsubmit="return saveScrollPositions(this);"><button type="submit" class="btn btn-primary btn-sm">like</button><input type="hidden" name="id" value="98"><input type="hidden" name="likes" value="5"><input type="hidden" name="scrollx" id="scrollx" value="0" /><input type="hidden" name="scrolly" id="scrolly" value="0" /></form></p></div><p class="lnktags">Tags: <a href="http://www.notable-quotes.com/r/reich_wilhelm.html">Wilhelm Reich</a></p><hr><ul class="pagination"><li class="disabled"><span>&laquo;</span></li><li class="active"><span>1</span></li><li><a href="law_quotes_ii.html">2</a></li><li><a href="law_quotes_iii.html">3</a></li><li><a href="law_quotes_iv.html">4</a></li><li><a href="law_quotes_v.html">5</a></li><li><a href="law_quotes_vi.html">6</a></li><li><a href="law_quotes_vii.html">7</a></li><li><a href="law_quotes_viii.html">8</a></li><li><a href="law_quotes_ix.html">9</a></li><li><a href="law_quotes_ix.html">&raquo;</a></li></ul>\t\t\t\t\r\n\t\t\t\t<br><br><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>\r\n<!-- Notable Quotes body -->\r\n<ins class="adsbygoogle"\r\n     style="display:inline-block;width:336px;height:280px"\r\n     data-ad-client="ca-pub-4793167219639586"\r\n     data-ad-slot="3750981025"></ins>\r\n<script>\r\n(adsbygoogle = window.adsbygoogle || []).push({});\r\n</script>\t\t\t</div>\t\r\n\t\t\t\t<div class="row footer">\r\n\t\t\t\t<div id="footer">\r\n\t<p><small>Copyright &copy; 2005 - 2017<a href="../index.html"> Notable Quotes</a>. All rights reserved. <a href="../subject_index.html"> Browse by subject</a> <a href="../author_index.html"> Browse by author</a></small></p>\r\n</div> <!-- end #footer -->\t\t\t\t</div>\r\n\t\t\t</div>\r\n\t\t\t<div class="col-md-2 sky">\r\n\t\t\t\t<div class="row">\r\n\t\t\t\t<div id="sidebar">\r\n<br>\r\n<script id="mNCC" language="javascript">\r\n   medianet_width = "160";\r\n   medianet_height = "600";\r\n   medianet_crid = "866579726";\r\n   medianet_versionId = "111299";\r\n   (function() {\r\n       var isSSL = \'https:\' == document.location.protocol;\r\n       var mnSrc = (isSSL ? \'https:\' : \'http:\') + \'//contextual.media.net/nmedianet.js?cid=8CUGXAUS1\' + (isSSL ? \'&https=1\' : \'\');\r\n       document.write(\'<scr\' + \'ipt type="text/javascript" id="mNSC" src="\' + mnSrc + \'"></scr\' + \'ipt>\');\r\n   })();\r\n</script>\r\n\r\n</div> <!-- end #sidebar -->\t\t\t\t</div>\r\n\t\t\t</div> \r\n\t\t</div> <!-- End #row -->\r\n\t</div> <!-- End #container -->\r\n\r\n    <!-- jQuery (necessary for Bootstrap\'s JavaScript plugins) -->\r\n<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>\r\n<!-- Include all compiled plugins (below), or include individual files as needed -->\r\n<script src="js/bootstrap.min.js"></script>\r\n\r\n\r\n<script type="text/javascript">\r\nwindow.scrollTo(0, 0);\r\n</script>  </body>\r\n</html>'

Two Data Points, One Match


Parse the site's contents

In [21]:
res_1 = re.search(b"<p class=\"quotation\">([^<]*)<\/p><p class=\"attribution\">([^,]*),\s*<em>([^<]*)",p_1)
output_1 = res_1.group(1).decode('UTF-8')
print(output_1)
output_2 = res_1.group(2).decode('UTF-8')
print(output_2)
output_3 = res_1.group(3).decode('UTF-8')
print(output_3)
Laws grind the poor, and rich men rule the law.
OLIVER GOLDSMITH
The Traveller

Post to Twitter and Save to Google (Two Data Point, One Match)

In [23]:
if (res_1 and (worksheet.row_values(worksheet.row_count)[1]) != output_1
          and (worksheet.row_values(worksheet.row_count)[2]) != output_2
          and (worksheet.row_values(worksheet.row_count)[3]) != output_3):
    # same as above but now comparing two values
    
    try:
        # Post to Twitter.
        status = api.PostUpdate('"%s" by: %s in: %s'%(output_1,output_2,output_3))
        print(status.text)
    except TwitterError:
        # Post to Twitter.
        status = api.PostUpdate('"%s" by, %s in, %s'%(output_1,output_2,output_3))
        print(status.text)

    # Save to Google only after Tweeting
    worksheet.append_row([now,output_1,output_2,output_3])
In [ ]: