<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      python 某音文件下載

      import time
      # from pyquery import PyQuery as pq
      import commonMethod
      import datetime
      import requests
      import re
      import os
      import json
      
      pattern_1 = '<source class="" src="http://v3-web.douyinvod.com/(.{486,488}) type="">'
      # pattern_2 = '<source class="" src="http://v26-web.douyinvod.com/(.{486,488}) type="">'
      # pattern_3 = '<source class="" src="http://www.douyin.com/aweme/v1/play/(.+) type="">'
      
      pattern_4='https://www.douyin.com/video/(\d+)'
      
      def get_info_by_pattern(text,pattern):
          p = re.compile(pattern)
          p_res = p.findall(text)
          return p_res
      
      def get_headdouyinvod_com():
          headers = {
              "Connection": "keep-alive",
              "Pragma": "no-cache",
              "Cache-Control": "no-cache",
              "sec-ch-ua": "\"Google Chrome\";v=\"95\", \"Chromium\";v=\"95\", \";Not A Brand\";v=\"99\"",
              "sec-ch-ua-mobile": "?0",
              "sec-ch-ua-platform": "\"Windows\"",
              "Upgrade-Insecure-Requests": "1",
              "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36",
              "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
              "Sec-Fetch-Site": "none",
              "Sec-Fetch-Mode": "navigate",
              "Sec-Fetch-User": "?1",
              "Sec-Fetch-Dest": "document",
              "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8"
          }
          return headers
      
      # 獲取抖音鏈接
      def get_douyin_url(driver1,sharl_url):
          try:
              if 'https' not in sharl_url:
                  sharl_url = 'https://www.douyin.com/video/' + sharl_url
              VID = ''
              p_res = get_info_by_pattern(sharl_url, pattern_4)
              if len(p_res) > 0:
                  VID = p_res[0]
      
              # driver1 = commonMethod.getDriver('',False)
              url = 'https://www.douyin.com'
              driver1.get(url)
              # driver1.delete_all_cookies()
              list_cooke = [
                  {'domain': '.douyin.com', 'expiry': 1698999663, 'httpOnly': False, 'name': 'VIDEO_FILTER_MEMO_SELECT',
                   'path': '/', 'secure': False, 'value': '%7B%22expireTime%22%3A1698999663897%2C%22type%22%3A1%7D'},
                 ...]
      
              for cook in list_cooke:
                  driver1.add_cookie(cook)
              time.sleep(5)
              driver1.refresh()
      
              # cookies = driver1.get_cookies()
              # print(cookies)
              # sharl_url = 'https://www.douyin.com/video/7294079788010999040'
              driver1.get(sharl_url)
              time.sleep(5)
              txt = driver1.execute_script("return document.documentElement.outerHTML")
              txt = txt.replace('amp;', '')
              # txt = pq(selenium_html)
              # pattern_1 = '<source class="" src="http://v3-web.douyinvod.com/(.+) type="">'
              # pattern_2 = '<source class="" src="http://v26-web.douyinvod.com/(.+) type="">'
      
              p_res = get_info_by_pattern(txt, pattern_1)
              if len(p_res) > 0:
                  p_res = p_res[0].replace('"', '')
                  # print(len(p_res))
                  herf1 = 'https://v3-web.douyinvod.com/' + p_res
                  print(herf1)
                  return herf1,VID
          except Exception as ex:
              print('獲取鏈接發生異常:',sharl_url,ex)
      
          return '',''
          # p_res = get_info_by_pattern(txt, pattern_2)
          # if len(p_res) > 0:
          #     p_res = p_res[0].replace('"', '')
          #     # print(len(p_res))
          #     herf1 = 'https://v26-web.douyinvod.com/' + p_res
          #     print(herf1)
          #     return herf1,VID
          # p_res = get_info_by_pattern(txt, pattern_3)
          # if len(p_res) > 0:
          #     p_res = p_res[0].replace('"', '')
          #     print(len(p_res))
          #     herf1 = 'https://www.douyin.com/aweme/v1/play/' + p_res
          #     print(herf1)
          #     return herf1,VID
          # return '',VID
      
      #下載抖音文件
      def dowfile_v3_web_douyinvod_com(file_url, fileName):
          page_size = 1024 * 128
          # url = "https://v3-web.douyinvod.com/4643edd0f5d68ed70fd6c6681f98ecdc/653b7807/video/tos/cn/tos-cn-ve-15c001-alinc2/ossMXydUtABkQozrA7g6NnEgHfeAOn9BkDhIAz/"
          # url='https://v3-web.douyinvod.com/4643edd0f5d68ed70fd6c6681f98ecdc/653b7807/video/tos/cn/tos-cn-ve-15c001-alinc2/ossMXydUtABkQozrA7g6NnEgHfeAOn9BkDhIAz/?a=6383&ch=26&cr=3&dr=0&lr=all&cd=0%7C0%7C0%7C3&cv=1&br=893&bt=893&cs=0&ds=3&ft=GN7rKGVVywIiRZm8Zmo~1u249EAp2yfbEvrK3ugu0mo0g3&mime_type=video_mp4&qs=1&rc=ZTpoODQzZmg3NGU8NjdlN0BpamZ4dGY6Zm92bjMzNGkzM0A0MDMvMjFgNTYxNmEuY2FgYSNtNi1ncjRvYXBgLS1kLTBzcw%3D%3D&btag=e00008000&dy_q=1698392554&feature_id=46a7bb47b4fd1280f3d3825bf2b29388&l=20231027154234B07D3936DE469D034161'
      
          headers = get_headdouyinvod_com()
          date = datetime.datetime.now()
          strstart = date.strftime("%Y-%m-%d-%H-%M-%S")
          print('開始下載:', strstart)
      
          try:
              response = requests.get(file_url, headers=headers, stream=True)
              # response = requests.get(url, headers=headers, params=params, stream=True)
              if response.status_code == 200 or response.status_code == 206:
                  headers = json.loads(str(response.headers).replace('"', '').replace('\'', '"'))
                  print(headers)
                  with(open(fileName, 'ab')) as f:
                      for chunk in response.iter_content(chunk_size=512):
                          if chunk:
                              f.write(chunk)
      
                  if 'Content-Range' in headers:
                      # Content_Range = str(headers['Content-Length'])
                      # total_length = int(Content_Range)
                      Content_Range = str(headers['Content-Range'])
                      total_length = int(Content_Range.split('/')[1])
                      if total_length > page_size:
                          rest_size = total_length - page_size
                          loop_count = int(rest_size / page_size)
                          if rest_size % page_size > 0:
                              loop_count += 1
                          if loop_count > 0:
                              flag_minus = False
                              for i in range(1, loop_count + 1):
                                  loop_index = i
                                  if flag_minus:
                                      loop_index -= 1
                                  sfrom = page_size * loop_index + 1
                                  sto = page_size * (loop_index + 1)
                                  headers['Range'] = 'bytes=%d-%d' % (sfrom, sto)
                                  print(loop_index, loop_count)
                                  try:
                                      # proxy_one = getIP()
                                      # proxies = {"https": "https://" + proxy_one}
                                      response = requests.get(url, headers=headers, stream=True)
                                      if response.status_code == 200 or response.status_code == 206:
                                          headers = json.loads(str(response.headers).replace('"', '').replace('\'', '"'))
                                          # print(headers)
                                          with(open(fileName, 'ab')) as f:
                                              for chunk in response.iter_content(chunk_size=512):
                                                  if chunk:
                                                      f.write(chunk)
                                      flag_minus = False
                                  except Exception as ex:
                                      print(ex)
                                      time.sleep(10)
                                      if str(ex).find('Max retries exceeded with url') > -1:
                                          print('Max retries exceeded with url')
                                          flag_minus = True
                                  time.sleep(1)
      
                              date = datetime.datetime.now()
                              strend = date.strftime("%Y-%m-%d %H:%M:%S")
                              print('完成下載:', strstart, strend)
      
          except Exception as ex:
              print('下載文件發生異常:',file_url,ex)
      
      # 下載抖音文件,
      def down_file(sharl_url_list,strDirectory):
          '''
          下載抖音文件
          :param sharl_url: 抖音詳細鏈接列表,類似:['https://www.douyin.com/video/7294079788010999040','https://www.douyin.com/video/7293552737067928868']
          :param strDirectory: 抖音文件存儲路徑,類似:D:/douyin_file_down/202310
          :return:
          '''
          # strDirectory = os.getcwd()
          # sharl_url = 'https://www.douyin.com/video/7294079788010999040'
          try:
              driver1 = commonMethod.getDriver('', False)
              for sharl_url in sharl_url_list:
                  file_url, VID = get_douyin_url(driver1, sharl_url)
                  # file_url, VID ='https://v3-web.douyinvod.com/4643edd0f5d68ed70fd6c6681f98ecdc/653b7807/video/tos/cn/tos-cn-ve-15c001-alinc2/ossMXydUtABkQozrA7g6NnEgHfeAOn9BkDhIAz/?a=6383&ch=26&cr=3&dr=0&lr=all&cd=0%7C0%7C0%7C3&cv=1&br=893&bt=893&cs=0&ds=3&ft=GN7rKGVVywIiRZm8Zmo~1u249EAp2yfbEvrK3ugu0mo0g3&mime_type=video_mp4&qs=1&rc=ZTpoODQzZmg3NGU8NjdlN0BpamZ4dGY6Zm92bjMzNGkzM0A0MDMvMjFgNTYxNmEuY2FgYSNtNi1ncjRvYXBgLS1kLTBzcw%3D%3D&btag=e00008000&dy_q=1698392554&feature_id=46a7bb47b4fd1280f3d3825bf2b29388&l=20231027154234B07D3936DE469D034161','7294079788010999040'
                  fileName = os.path.join(strDirectory, VID + '.mp4')
                  if len(file_url) > 0:
                      dowfile_v3_web_douyinvod_com(file_url, fileName)
              driver1.close()
          except Exception as ex:
              print(ex)
      
      if __name__ == "__main__":
          # strDirectory = os.getcwd()
          # 保存路徑
          strDirectory = 'D:/douyin/file/202310'
          # sharl_url='https://www.douyin.com/video/7293555365818453274'
          sharl_url_list=['https://www.douyin.com/video/7293555365818453274',
                          'https://www.douyin.com/video/7293552737067928868',
                          'https://www.douyin.com/video/7293555206388780324']
          down_file(sharl_url_list, strDirectory)
      View Code

       

      posted on 2023-10-27 17:08  shaomine  閱讀(180)  評論(0)    收藏  舉報

      主站蜘蛛池模板: 无码国产偷倩在线播放| 人妻少妇精品系列一区二区| 亚洲国产精品日韩在线| 国产精品午夜福利免费看| 国产在线观看黄| 丝袜人妻一区二区三区网站| 和黑人中出一区二区三区| 亚洲第一狼人成人综合网| 国产精品理论片在线观看| 亚洲色大成网站WWW永久麻豆| 中文字幕无码不卡在线| 又大又黄又粗高潮免费| 亚洲日韩一区二区| 国产高清精品在线91| 一区二区三区四区高清自拍 | av亚洲一区二区在线| 国产av永久无码天堂影院| 中文人妻熟妇乱又伦精品| 四虎成人在线观看免费| 亚洲天堂亚洲天堂亚洲色图| 精品 日韩 国产 欧美 视频| 响水县| 国产在线拍揄自揄拍无码| 精品亚洲国产成人av| 玩弄放荡人妻少妇系列| 强奷白丝美女在线观看| 国产精品伦人一久二久三久| 久久不卡精品| 亚洲精品天堂在线观看| 国产精品一区二区三区91| 欧美喷潮最猛视频| 亚洲欧美日韩高清一区二区三区| 精品国产粉嫩一区二区三区| 国产欧美国日产高清| 99久久精品久久久久久婷婷| 国产精品无码久久久久AV| 欧美国产日韩久久mv| 亚洲AV无码一二区三区在线播放| 国产偷窥熟女高潮精品视频| 日本三级理论久久人妻电影| 国产精品一二三区久久狼|