# wk15_1214_lineStickerDownload 1. 課本原始檔 2. 影音教學 step by step 3. stickershop 貼圖完整 4. emojishop 表情貼 5. chatGpt - local jpg 6. chatGpt - line png ```python ## 課本原始檔 import requests, json, os from bs4 import BeautifulSoup #url = 'https://store.line.me/stickershop/product/8991459/zh-Hant' #人的日常 url = 'https://store.line.me/stickershop/product/19650/zh-Hant' #黏黏怪物 html = requests.get(url) sp = BeautifulSoup(html.text, 'html.parser') #datas = sp.find_all('li', {'class':'mdCMN09Li FnStickerPreviewItem'}) datas = sp.find_all('li', {'class':'mdCMN09Li FnStickerPreviewItem animation-sticker'}) #class可能會隨著貼圖不同而不同,要記得改!! # 建立目錄儲存圖片 images_dir= "line/" if not os.path.exists(images_dir): os.mkdir(images_dir) for data in datas: imginfo = json.loads(data.get('data-preview')) id = imginfo['id'] imgfile = requests.get(imginfo['staticUrl']) full_path = images_dir + id + '.png' with open(full_path, 'wb') as f: f.write(imgfile.content) print(full_path) ``` line/374495886.png line/374495887.png line/374495888.png line/374495889.png line/374495890.png line/374495891.png line/374495892.png line/374495893.png line/374495894.png line/374495895.png line/374495896.png line/374495897.png line/374495898.png line/374495899.png line/374495900.png line/374495901.png line/374495902.png line/374495903.png line/374495904.png line/374495905.png line/374495906.png line/374495907.png line/374495908.png line/374495909.png ```python ``` ```python ``` ```python #lineSticker 教學-1 import requests, json, os from bs4 import BeautifulSoup ``` ```python #lineSticker 教學-2 url = 'https://store.line.me/stickershop/product/8991459/zh-Hant' html = requests.get(url) html ``` ```python #lineSticker 教學-3 html.text ``` ```python #lineSticker 教學-4 sp = BeautifulSoup(html.text, 'html.parser') sp ``` ```python #lineSticker 教學-5 sp.title.text ``` ```python #lineSticker 教學-6 sp.find_all('li', {'class':'mdCMN09Li FnStickerPreviewItem static-sticker'}) ``` ```python ``` ```python #lineSticker 教學-7 sp = BeautifulSoup(html.text, 'html.parser') datas = sp.find_all('li', {'class':'mdCMN09Li FnStickerPreviewItem static-sticker'}) print(datas) ``` ```python #lineSticker 教學-8 len(datas) ``` ```python #lineSticker 教學-9 for data in datas: print(data.get('data-preview')) ``` ```python #lineSticker 教學-10 for data in datas: imginfo = json.loads(data.get('data-preview')) print(imginfo['id']) print(imginfo['staticUrl']) ``` ```python #lineSticker 教學-11 imges_dir = "line_image/" if not os.path.exists(imges_dir): os.mkdir(imges_dir) for data in datas: imginfo = json.loads(data.get('data-preview')) id = imginfo['id'] imgfile = requests.get(imginfo['staticUrl']) full_path = imges_dir + id + '.png' with open(full_path, 'wb') as f: f.write(imgfile.content) print(full_path) ``` ```python ``` ```python ``` ```python #stickershop 完整 import requests, json, os from bs4 import BeautifulSoup url = 'https://store.line.me/stickershop/product/19650/zh-Hant' #黏黏怪物 html = requests.get(url) sp = BeautifulSoup(html.text, 'html.parser') datas = sp.find_all('li', {'class':'mdCMN09Li FnStickerPreviewItem static-sticker'}) imges_dir = "line_image/" if not os.path.exists(imges_dir): os.mkdir(imges_dir) for data in datas: imginfo = json.loads(data.get('data-preview')) id = imginfo['id'] imgfile = requests.get(imginfo['staticUrl']) full_path = imges_dir + id + '.png' with open(full_path, 'wb') as f: f.write(imgfile.content) print(full_path) ``` ```python ``` ```python ``` ```python #表情貼-1 import requests, json, os from bs4 import BeautifulSoup #url = 'https://store.line.me/stickershop/product/8991459/zh-Hant' #人的日常 url = 'https://store.line.me/emojishop/product/646b23ff903b5543729ffa4d/zh-Hant' #超實用❤生活用語對話框 #url = 'https://store.line.me/emojishop/product/61b04cbaf864dd7f3763ab8b/zh-Hant' #超實用❤手勢/符號 動態表情貼 html = requests.get(url) html ``` ```python #表情貼-2 sp = BeautifulSoup(html.text, 'html.parser') #datas = sp.find_all('li', {'class':'mdCMN09Li FnStickerPreviewItem static-sticker'}) #datas = sp.find_all('li', {'class':'mdCMN09Li FnStickerPreviewItem'}) #後面沒有static-sticker!!! datas = sp.find_all('li', {'class':'mdCMN09Li FnStickerPreviewItem'}) print(datas) ``` ```python #表情貼-3 imges_dir = "line_image_emojishop/生活用語對話框/" if not os.path.exists(imges_dir): os.mkdir(imges_dir) for data in datas: imginfo = json.loads(data.get('data-preview')) id = imginfo['id'] imgfile = requests.get(imginfo['staticUrl']) full_path = imges_dir + id + '.png' with open(full_path, 'wb') as f: f.write(imgfile.content) print(full_path) ``` ```python ``` ```python ## chatGpt local jpg import shutil source_path = r'C:\zzz\111.png' #檔案名稱是.png!!! destination_path = r'C:\zzz\1.png' # 複製文件 shutil.copyfile(source_path, destination_path) print(f'已從 {source_path} 複製到 {destination_path}') ``` 已從 C:\zzz\111.png 複製到 C:\zzz\1.png ```python ## chatGpt line png import requests import os url = 'https://stickershop.line-scdn.net/stickershop/v1/sticker/374495886/iPhone/sticker@2x.png?v=6' #特定一個貼圖的網址 save_path = r'C:\zzz\3.jpg' #response = requests.get(url, stream=True) response = requests.get(url) with open(save_path, 'wb') as file: for chunk in response.iter_content(chunk_size=8192): file.write(chunk) print(f'已從 {url} 下載並保存到 {save_path}') ``` 已從 https://stickershop.line-scdn.net/stickershop/v1/sticker/374495886/iPhone/sticker@2x.png?v=6 下載並保存到 C:\zzz\3.jpg