這是原始碼,有沒有python資深大佬幫忙寫一個tkinter的視窗
import requests
import re
from bs4 import BeautifulSoup
from tkinter import *
from tkinter import messagebox
print('此程式為獲取b站視頻封面的Python程式使用Pyinstaller封裝')
while True:
try:
while True:
Ua = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36'} # Ua 偽裝
content = input('輸入av或BV號(請務必在開頭加上av或BV):')
Reset_content = f'https://www.bilibili.com/video/{content}'
request = requests.get(Reset_content, Ua) # 訪問視頻主頁
soup = BeautifulSoup(request.text, 'lxml') # 煲湯
title = soup.find('title') # 找到title
x = str(title)
rstr = r"[\/\\\:\*\?\"\<\>\|]" # '/ \ : * ? " < > |'
new_title = re.sub(rstr, " ", x) # 替換為下劃線
new_new_title = new_title[28:] # 去掉一些沒用的字符
new_new_new_title = new_new_title[0:-34] # 去掉沒用的字符
image_json = soup.find('meta', itemprop = "image") # 獲取視頻封面URL
image = image_json.get('content') # 找到具體URL
download = requests.get(image, Ua) # 訪問圖片地址
with open(f'{new_new_new_title}.jpg', 'wb') as f: # 下載圖片
f.write(download.content)
print(f'視頻標題為:{new_new_new_title} 封面地址為:{image}, 檔案已自動保存到程式作業目錄')
except:
print('錯誤 請檢查AV或BV號是否有誤')
continue
uj5u.com熱心網友回復:
tkinter就是搞不明白轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/261897.html
