Advertisement
Guest User

One random quote

a guest
Dec 4th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. from bs4 import BeautifulSoup
  4. import requests
  5. import re
  6.  
  7. head = {"Cache-Control": "no-cache",
  8.         "Pragma": "no-cache",
  9.         "Expires": "Thu, 01 Jan 1970 00:00:00 GMT"
  10. }
  11. doc = requests.get("http://danstonchat.com/random0.html", headers=head)
  12. if doc.status_code != 200:
  13.     exit()
  14. soup = BeautifulSoup(doc.content, "html.parser")
  15. fst = soup.find_all("div", class_="item", limit=1)
  16. quote = fst[0].find("a")
  17.  
  18. while quote.br is not None:
  19.     quote.br.replace_with("\n")
  20. str = re.sub("\n ", "\n", quote.get_text())
  21. print(str)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement