-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscrape.py
More file actions
38 lines (30 loc) · 1.02 KB
/
scrape.py
File metadata and controls
38 lines (30 loc) · 1.02 KB
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
35
36
37
38
import sys
import requests
from bs4 import BeautifulSoup
import json
import urllib.request
import certifi
from PIL import Image
# Get html
url = sys.argv[1]
req = requests.get(url)
content = req.text
# Get elements that contain stickers
soup = BeautifulSoup(content, features="html.parser")
sticker_elements = soup.find_all("li", {"class": "FnStickerPreviewItem"})
for index, sticker_element in enumerate(sticker_elements):
# Get url of sticker
animation_url = json.loads(sticker_element["data-preview"])["animationUrl"]
file_name = str(index) + ".png"
# Download sticker
with urllib.request.urlopen(animation_url, cafile=certifi.where()) as data, open(file_name, "wb") as output:
data = data.read()
output.write(data)
# Make sticker loop
apng = Image.open(file_name)
apng.format = "apng"
apng.info["default_image"] = True
if apng.mode != 'RGBA':
apng = apng.convert("RGBA")
file_name = str(index) + ".gif"
apng.save(file_name, loop=0, disposal=2, save_all=True)