Created
November 30, 2017 09:53
-
-
Save DoubleMalt/4a7b979b55b5ce5d0ebaf78c9134db46 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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