Skip to content

Instantly share code, notes, and snippets.

@DoubleMalt
Created November 30, 2017 09:53
Show Gist options
  • Save DoubleMalt/4a7b979b55b5ce5d0ebaf78c9134db46 to your computer and use it in GitHub Desktop.
Save DoubleMalt/4a7b979b55b5ce5d0ebaf78c9134db46 to your computer and use it in GitHub Desktop.
import re
from urllib2 import urlopen
import BeautifulSoup as BS
def main():
url = "http://quotes.yourdictionary.com/theme/marriage/"
page = urlopen(url).read()
soup = BS.BeautifulSoup(page)
all_quotes = soup.findAll(attrs={"class": "QuotesAndNotes"})
for quote in all_quotes[0:5]:
quote_text = quote.findAll("p")[0].text
quote_author = quote.findAll("a")[1].text
quote_source = ""
if len(quote.findAll("i")):
quote_source = quote.findAll("i")[0].text
print quote_text + " - " + quote_author + " - " + quote_source
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment