Created
November 9, 2021 14:45
-
-
Save GiammaCarioca/6e0785188e8c7ffb9c59b5e0024c92c5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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