Skip to content

Instantly share code, notes, and snippets.

@GiammaCarioca
Created November 9, 2021 14:45
Show Gist options
  • Select an option

  • Save GiammaCarioca/6e0785188e8c7ffb9c59b5e0024c92c5 to your computer and use it in GitHub Desktop.

Select an option

Save GiammaCarioca/6e0785188e8c7ffb9c59b5e0024c92c5 to your computer and use it in GitHub Desktop.
from bs4 import BeautifulSoup
import re
import requests
import json
url = "https://motivationgrid.com/rihanna-quotes"
r = requests.get(url)
soup = BeautifulSoup(r.text, 'html.parser')
quotesList = []
quotes = []
for item in soup.findAll('li', text=re.compile("– Rihanna")):
quotes.append(re.findall('\“(.+?)\”', str(item)))
list(map(quotesList.extend, quotes))
def formatText(content):
formattedText = []
for item in content:
formattedText.append(str(item).replace("’", "'"))
return formattedText
with open("quotes.json", "w", encoding='utf8') as write_file:
json.dump(formatText(quotesList), write_file, ensure_ascii=False, indent=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment