from bs4 importBeautifulSoupimportrequestsimportos,re,timeimporturllib3from win32com.client importDispatchclassDownloadVideo:def __init__(self):
self.r=requests.session()
self.url=self.get_url()
self.download_urla=[]
self.download_urlb=[]
self.url_set=["%s/shipin/list-短视频.html"%self.url]#获取最新网址
defget_url(self):
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
a=self.r.get('https://www.k58.com',verify=False)
b=a.urlreturnb#几页内容的网址
defurl_set1(self,n):if n==2:
url="%s/shipin/list-短视频-2.html"%self.url
self.url_set.append(url)elif n>=3:
m=n+1
for i in range(2,m):
url="%s/shipin/list-短视频-%d.html"%(self.url,i)
self.url_set.append(url)else:pass
#分别加载每一个页内容的网址
defdownload_url1(self):for j inself.url_set:
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
r=self.r.get(j,verify=False)
sp1=r.content
soup= BeautifulSoup(sp1, "html.parser")
sp2= soup.find_all(class_="shown")for i insp2:
self.download_urla.append(u)#分别获取各个视频的下载链接
defdownload_url2(self):for i inself.download_urla:
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
soup= BeautifulSoup(sp1, "html.parser")
sp2= soup.find_all(class_="form-control input-sm copy_btn app_disable")for j insp2:
self.download_urlb.append(url2)#将链接写入txt中
defthunder_download(self):try:
thunder= Dispatch("ThunderAgent.Agent64.1")for i inself.download_urlb:
time.sleep(2)except:print("请下载迅雷,并在其设置中心的下载管理中设置为一键下载")defmkdir(self,path):
folder=os.path.exists(path)if notfolder:
file_name=time.strftime('%Y%m%d_%H%M%S.txt')
with open(r"D:\AAAAA\%s"%file_name,'a') as f:
f.write(c+"\n")if __name__ == '__main__':