-
Notifications
You must be signed in to change notification settings - Fork 35
/
scrape_emojis.py
34 lines (31 loc) · 1.21 KB
/
scrape_emojis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import aiohttp
from bs4 import BeautifulSoup
import asyncio
import json
async def emoji_thing():
emojis = None
async with aiohttp.ClientSession() as client:
async with client.get('https://unicode.org/emoji/charts/full-emoji-list.html') as resp:
assert resp.status == 200
soup = BeautifulSoup(await resp.text(), 'html.parser')
tables = [
[
[td.find('img')['src'] if td.find('img') is not None else td.get_text(strip=False) for td in tr.find_all('td')]
for tr in table.find_all('tr')
]
for table in soup.find_all('table')
]
emojis = {}
for table in tables:
for row in table:
if len(row) > 4:
moji = row[3].replace('…', '').strip()
emojis[row[2]] = moji.replace('data:image/png;base64,', '')
if emojis:
with open('emojis.json', 'w') as f:
f.write(json.dumps(emojis))
if __name__ == "__main__":
loop = asyncio.new_event_loop();
asyncio.set_event_loop(loop)
loop.run_until_complete(emoji_thing())
loop.close()