# wk15_1214_lineStickerDownload <pre> 1. 課本原始檔 2. 影音教學 step by step 3. stickershop 貼圖完整 4. emojishop 表情貼 5. chatGpt - local jpg 6. chatGpt - line png </pre> <pre> In [ ]: ## 課本原始檔 import requests, json, os from bs4 import BeautifulSoup url = 'https://store.line.me/stickershop/product/8991459/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 static-sticker'}) # 建立目錄儲存圖片 images_dir= "line_image/" 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) </pre> <pre> In [ ]: #lineSticker 教學-1 import requests, json, os from bs4 import BeautifulSoup In [ ]: #lineSticker 教學-2 url = 'https://store.line.me/stickershop/product/8991459/zh-Hant' html = requests.get(url) html In [ ]: #lineSticker 教學-3 html.text In [ ]: #lineSticker 教學-4 sp = BeautifulSoup(html.text, 'html.parser') sp In [ ]: #lineSticker 教學-5 sp.title.text In [ ]: #lineSticker 教學-6 sp.find_all('li', {'class':'mdCMN09Li FnStickerPreviewItem static-sticker'}) In [ ]: #lineSticker 教學-7 sp = BeautifulSoup(html.text, 'html.parser') datas = sp.find_all('li', {'class':'mdCMN09Li FnStickerPreviewItem static-sticker'}) print(datas) In [ ]: #lineSticker 教學-8 len(datas) In [ ]: #lineSticker 教學-9 for data in datas: print(data.get('data-preview')) In [ ]: #lineSticker 教學-10 for data in datas: imginfo = json.loads(data.get('data-preview')) print(imginfo['id']) print(imginfo['staticUrl']) In [ ]: #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) In [ ]: #stickershop 完整 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/24885624/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) In [3]: #表情貼-1 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/24885624/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 Out[3]: <Response [200]> In [4]: #表情貼-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'}) datas = sp.find_all('li', {'class':'mdCMN09Li FnStickerPreviewItem'}) print(datas) In [5]: #表情貼-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) line_image_emojishop/生活用語對話框/001.png line_image_emojishop/生活用語對話框/002.png line_image_emojishop/生活用語對話框/003.png line_image_emojishop/生活用語對話框/004.png line_image_emojishop/生活用語對話框/005.png line_image_emojishop/生活用語對話框/006.png line_image_emojishop/生活用語對話框/007.png line_image_emojishop/生活用語對話框/008.png line_image_emojishop/生活用語對話框/009.png line_image_emojishop/生活用語對話框/010.png line_image_emojishop/生活用語對話框/011.png line_image_emojishop/生活用語對話框/012.png line_image_emojishop/生活用語對話框/013.png line_image_emojishop/生活用語對話框/014.png line_image_emojishop/生活用語對話框/015.png line_image_emojishop/生活用語對話框/016.png line_image_emojishop/生活用語對話框/017.png line_image_emojishop/生活用語對話框/018.png line_image_emojishop/生活用語對話框/019.png line_image_emojishop/生活用語對話框/020.png line_image_emojishop/生活用語對話框/021.png line_image_emojishop/生活用語對話框/022.png line_image_emojishop/生活用語對話框/023.png line_image_emojishop/生活用語對話框/024.png line_image_emojishop/生活用語對話框/025.png line_image_emojishop/生活用語對話框/026.png line_image_emojishop/生活用語對話框/027.png line_image_emojishop/生活用語對話框/028.png line_image_emojishop/生活用語對話框/029.png line_image_emojishop/生活用語對話框/030.png line_image_emojishop/生活用語對話框/031.png line_image_emojishop/生活用語對話框/032.png line_image_emojishop/生活用語對話框/033.png line_image_emojishop/生活用語對話框/034.png line_image_emojishop/生活用語對話框/035.png line_image_emojishop/生活用語對話框/036.png line_image_emojishop/生活用語對話框/037.png line_image_emojishop/生活用語對話框/038.png line_image_emojishop/生活用語對話框/039.png line_image_emojishop/生活用語對話框/040.png In [ ]: ## chatGpt local jpg import shutil source_path = r'C:\zzz\111.jpg' destination_path = r'C:\zzz\2.jpg' # 複製文件 shutil.copyfile(source_path, destination_path) print(f'已從 {source_path} 複製到 {destination_path}') In [10]: ## chatGpt line png import requests import os url = 'https://stickershop.line-scdn.net/stickershop/v1/sticker/230054638/android/sticker.png?v=1' 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/230054638/android/sticker.png?v=1 下載並保存到 C:\zzz\3.jpg </pre>
{"title":"wk15","description":"wk15_1214_lineStickerDownload","contributors":"[{\"id\":\"4f0ea7d8-a994-4abc-a066-938bfab2315c\",\"add\":6455,\"del\":9}]"}
Expand menu