欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python爬蟲爬取某網(wǎng)站視頻的示例代碼

 更新時(shí)間:2021年02月20日 09:58:23   作者:badbadboy  
這篇文章主要介紹了python爬蟲爬取某網(wǎng)站視頻的示例代碼,代碼簡(jiǎn)單易懂,對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

把獲取到的下載視頻的url存放在數(shù)組中(也可寫入文件中),通過(guò)調(diào)用迅雷接口,進(jìn)行自動(dòng)下載。(請(qǐng)先下載迅雷,并在其設(shè)置中心的下載管理中設(shè)置為一鍵下載)

實(shí)現(xiàn)代碼如下:

from bs4 import BeautifulSoup
import requests
import os,re,time
import urllib3
from win32com.client import Dispatch
class DownloadVideo:
  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]
  #獲取最新網(wǎng)址
  def get_url(self):
    urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
    a=self.r.get('https://www.k58.com',verify=False)
    b=a.url
    return b
  #幾頁(yè)內(nèi)容的網(wǎng)址
  def url_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
  #分別加載每一個(gè)頁(yè)內(nèi)容的網(wǎng)址
  def download_url1(self):
    for j in self.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 in sp2:
        url1=re.findall('<a href="(.*?)" rel="external nofollow" ',str(i))
        u=self.url+url1[0]
        self.download_urla.append(u)
  #分別獲取各個(gè)視頻的下載鏈接
  def download_url2(self):
    for i in self.download_urla:
      urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
      r=self.r.get(i,verify=False)
      sp1=r.content
      soup = BeautifulSoup(sp1, "html.parser")
      sp2 = soup.find_all(class_="form-control input-sm copy_btn app_disable")
      for j in sp2:
        url2=j["data-clipboard-text"]
        self.download_urlb.append(url2)
        #將鏈接寫入txt中
        # self.write_txt(url2)
  #迅雷下載
  def thunder_download(self):
    try:
      thunder = Dispatch("ThunderAgent.Agent64.1")
      for i in self.download_urlb:
        thunder.AddTask(i)
        thunder.CommitTasks()
        time.sleep(2)
    except:
      print("請(qǐng)下載迅雷,并在其設(shè)置中心的下載管理中設(shè)置為一鍵下載")

  def mkdir(self,path):
    folder = os.path.exists(path)
    if not folder:
      os.makedirs(path)
    else:
      pass
  def write_txt(self,c):
    self.mkdir(r"D:\AAAAA")
    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__':
  d=DownloadVideo()
  #數(shù)字表示幾頁(yè)的內(nèi)容
  d.url_set1(5)
  d.download_url1()
  d.download_url2()
  d.thunder_download()

到此這篇關(guān)于python爬蟲爬取某網(wǎng)站視頻的示例代碼的文章就介紹到這了,更多相關(guān)python爬蟲爬取網(wǎng)站視頻內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • python標(biāo)準(zhǔn)庫(kù)之time模塊的語(yǔ)法與簡(jiǎn)單使用

    python標(biāo)準(zhǔn)庫(kù)之time模塊的語(yǔ)法與簡(jiǎn)單使用

    在平常的代碼中,我們常常需要與時(shí)間打交道,那么在Python中,與時(shí)間處理有關(guān)的模塊就包括:time、datetime以及calendar,這篇文章主要給大家介紹了關(guān)于python標(biāo)準(zhǔn)庫(kù)之time模塊的語(yǔ)法與使用的相關(guān)資料,需要的朋友可以參考下
    2021-08-08
  • Python模擬簡(jiǎn)單電梯調(diào)度算法示例

    Python模擬簡(jiǎn)單電梯調(diào)度算法示例

    這篇文章主要介紹了Python模擬簡(jiǎn)單電梯調(diào)度算法,涉及Python線程、隊(duì)列、時(shí)間延遲等相關(guān)操作技巧,需要的朋友可以參考下
    2018-08-08
  • Python正則獲取、過(guò)濾或者替換HTML標(biāo)簽的方法

    Python正則獲取、過(guò)濾或者替換HTML標(biāo)簽的方法

    這篇文章主要介紹了Python通過(guò)正則表達(dá)式獲取、過(guò)濾或者替換HTML標(biāo)簽的方法,感興趣的小伙伴們可以參考一下
    2016-01-01
  • Python Flask框架擴(kuò)展操作示例

    Python Flask框架擴(kuò)展操作示例

    這篇文章主要介紹了Python Flask框架擴(kuò)展操作,結(jié)合實(shí)例形式分析了Python Flask-Script擴(kuò)展命令行操作實(shí)現(xiàn)方法,需要的朋友可以參考下
    2019-05-05
  • Python使用type關(guān)鍵字創(chuàng)建類步驟詳解

    Python使用type關(guān)鍵字創(chuàng)建類步驟詳解

    在本文里我們給讀者們整理了關(guān)于Python如何使用type關(guān)鍵字創(chuàng)建類的相關(guān)知識(shí)點(diǎn),需要的朋友們參考學(xué)習(xí)下。
    2019-07-07
  • python Elasticsearch索引建立和數(shù)據(jù)的上傳詳解

    python Elasticsearch索引建立和數(shù)據(jù)的上傳詳解

    在本篇文章里小編給大家整理的是關(guān)于基于python的Elasticsearch索引的建立和數(shù)據(jù)的上傳的知識(shí)點(diǎn)內(nèi)容,需要的朋友們參考下。
    2019-08-08
  • 老生常談python中的重載

    老生常談python中的重載

    所謂重載,就是多個(gè)相同函數(shù)名的函數(shù),根據(jù)傳入的參數(shù)個(gè)數(shù),參數(shù)類型而執(zhí)行不同的功能。所以函數(shù)重載實(shí)質(zhì)上是為了解決編程中參數(shù)可變不統(tǒng)一的問(wèn)題。這篇文章主要介紹了老生常談python中的重載,需要的朋友可以參考下
    2018-11-11
  • Python plt.imshow函數(shù)及其參數(shù)使用

    Python plt.imshow函數(shù)及其參數(shù)使用

    plt.imshow()是Matplotlib庫(kù)中的一個(gè)函數(shù),主要用于顯示圖像或矩陣數(shù)據(jù),本文主要介紹了Python plt.imshow函數(shù)及其參數(shù)使用,具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-02-02
  • 解決一個(gè)pandas執(zhí)行模糊查詢sql的坑

    解決一個(gè)pandas執(zhí)行模糊查詢sql的坑

    這篇文章主要介紹了解決一個(gè)pandas執(zhí)行模糊查詢sql的坑,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2021-03-03
  • 實(shí)例講解python中的序列化知識(shí)點(diǎn)

    實(shí)例講解python中的序列化知識(shí)點(diǎn)

    本篇文章通過(guò)代碼實(shí)例給大家詳細(xì)分享了關(guān)于python中的序列化知識(shí)點(diǎn)內(nèi)容,有興趣的朋友們可以學(xué)習(xí)下。
    2018-10-10

最新評(píng)論