Created
July 15, 2018 17:23
-
-
Save clamytoe/eddc08a212248215a4add96404da39d4 to your computer and use it in GitHub Desktop.
emoji.py
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
| import requests | |
| from bs4 import BeautifulSoup | |
| def get_soup(): | |
| url = 'https://www.webpagefx.com/tools/emoji-cheat-sheet/' | |
| page = requests.get(url) | |
| if page.ok: | |
| soup = BeautifulSoup(page.content, 'html.parser') | |
| spans = soup.find_all('span', {'class': 'name'}) | |
| return spans | |
| return None | |
| def parse_soup(soup): | |
| for span in soup: | |
| alt = span.alternatives | |
| name = span.text | |
| emoji = r'"\N{' + name.replace('_', ' ') + r'}"' | |
| try: | |
| print(eval(emoji), end='') | |
| print(f': {name}', end='\n') | |
| except SyntaxError: | |
| pass | |
| def main(): | |
| soup = get_soup() | |
| parse_soup(soup) | |
| if __name__ == '__main__': | |
| main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment