Skip to content

Instantly share code, notes, and snippets.

@joshdabosh
Created February 7, 2019 22:18
Show Gist options
  • Save joshdabosh/a74d8ec1252a09c5fae2e6b878ec0561 to your computer and use it in GitHub Desktop.
Save joshdabosh/a74d8ec1252a09c5fae2e6b878ec0561 to your computer and use it in GitHub Desktop.
Scrapes codecandies.com quotes and puts them into quotes.txt
from bs4 import BeautifulSoup as bs
import requests
page = requests.get("https://codecandies.com/")
soup = bs(page.content, "html.parser")
main = soup.find("div", {"class":"wrapper"})
quotes = []
for a in main.findAll("div", {"class":"section-inner"}):
for b in a.findAll("div", {"class":"posts"}):
for post in b.findAll("div", {"class": "post-container"}):
for post_inner in post.findAll("div", {"class": "type-post"}):
for post_content in post_inner.findAll("div", {"class": "post-content"}):
for blockquote in post_content.findAll("blockquote"):
for pre in blockquote.findAll("pre"):
quotes.append(pre.text.strip())
with open("quotes.txt", "w") as f:
q = "\n\n".join(quotes)
f.write(q)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment