阿里1688产品图片和视频资料下载
生活随笔
收集整理的這篇文章主要介紹了
阿里1688产品图片和视频资料下载
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
通過爬蟲和gui界面做成簡易的exe文件,
目前已經棄用(測試版)
以下是gui界面設置,
win()?方法是居中+凍結窗體設置,單獨列出提升可讀性也方便組裝(可以自己設置一些簡易gui界面模版方便以后直接填充)
text()?設置單行輸入框、可變數據(網址)和功能鍵
from tkinter import messagebox import requests, re from bs4 import BeautifulSoup import tkinter from tkinter.constants import CURRENT # import sys # import os# 設置絕對路徑 # def get_ico_src(relative_src): # if getattr(sys, "frozen", False): # base_path = sys._MEIPASS # else: # base_path = os.path.abspath(".") # return os.path.join(base_path, relative_src) # icon_src=get_ico_src(os.path.join("resources","versioncuecs2.ico"))class MainForm():def __init__(self):# 設置一個頁面self.root = tkinter.Tk() # 設置頁面總標題self.root.title('啦啦啦專屬')# 界面logoself.root.iconbitmap(icon_src)# 設置窗口self.win()# 設置背景顏色self.root["background"] = "orange"# 輸入處理self.text()self.root.mainloop()def win(self):self.screen_width = self.root.winfo_screenwidth()self.screen_height = self.root.winfo_screenheight()x = (self.screen_width - 500) / 2y = (self.screen_height - 90) / 2# 設置居中窗口self.root.geometry("500x90+%d+%d" % (x, y))# 禁止修改窗體self.root.resizable(width=False,height=False)def text(self):self.content = tkinter.StringVar()self.entry = tkinter.Entry(self.root,width=50,textvariable=self.content,font=('微軟雅黑',20))self.button = tkinter.Button(self.root, text='確定', fg="black", font=("微軟雅黑", 12))self.button.bind('<Button-1>', self.task)self.entry.pack()self.button.pack()if __name__ == "__main__":MainForm()?程序核心,
?通過請求客戶給予的商品界面網址,下載該商品的主視頻和圖片資料
設置多個報錯是為了方便以后的維護
cookie的設置還可以進一步優化,比如會話(session)
# 主程序def task(self, event):headers = {"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36","cookie": "保密,自己設"}search_url = self.entry.get()res = requests.get(search_url, headers=headers)soup = BeautifulSoup(res.text, "html.parser")try:data = soup.find("ul", class_="nav-tabs").find_all("li")except:messagebox.showerror("錯誤提示", "網址選擇錯誤!!!")self.root.protocol("WM_DELETE_WINDOW", self.root.destroy())obj_01 = re.compile(r'"original":"(.*?)"}', re.S)for photo_url in data:# li標簽 , class="tab-trigger"屬性 , data-imgs文件位置result_url = obj_01.findall(photo_url.get("data-imgs"))# print(result_url[0])file_01 = result_url[0].split("ibank/")[-1]file_name = file_01.replace("/", "p")# print(file_name)try:result_res = requests.get(result_url[0])with open(file_name, mode="wb") as f:f.write(result_res.content)except:messagebox.showerror("錯誤提示", "下載失敗!!!")self.root.protocol("WM_DELETE_WINDOW", self.root.destroy())messagebox.showinfo("溫馨提示", "下載完成!!!")self.content.set("")源碼:
CSDN-/阿里1688資料.py at 8c65a1b0ee133bf98eaee1acd905910d8337f7fe · thinkloading/CSDN- · GitHub
鑒于當前普遍的圖片和滑塊驗證碼
可以通過selenium登陸獲取cookie
再通過以下的轉換公式去處理成requests可用的格式
感興趣的可以自己去試試,這邊不在展開? <? 危(/▽\)? >
# res爬蟲kookie轉給selenium re = requests.get(url) cookies = res.cookies.get_dict() for k, v in cookies.items():driver.add_cookie({"name": k, "value": v})# selenium的cookie轉res for cookie in cookies_1:cookies[cookie['name']] = cookie['value']點個贊再走唄(>v<)
總結
以上是生活随笔為你收集整理的阿里1688产品图片和视频资料下载的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 前端剑法第二式————淬焰
- 下一篇: 商业智能,数据仓库,ETL,数仓调度工具