1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關(guān)咨詢
      選擇下列產(chǎn)品馬上在線溝通
      服務(wù)時(shí)間:8:30-17:00
      你可能遇到了下面的問題
      關(guān)閉右側(cè)工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
      python知識星球文件下載-創(chuàng)新互聯(lián)
      #!/usr/bin/python3
      # -*- coding: UTF-8 -*-
      
      import requests
      import json
      from urllib.parse import quote
      import os
      from pyquery import PyQuery as pq
      import datetime
      
      headers = {
          'Authorization': '37923FBC-C87D-454C-902D-A81DB0834605',
          'x-request-id': "73e67a6f-cf88-4c10-26da-a30441464ed5",
          'accept': "application/json, text/plain, */*",
          'host': "api.zsxq.com",
          'connection': "keep-alive",
          'referer': "https://wx.zsxq.com/dweb/",
          'user-agent': "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36",
      }
      
      def readtopicurl(filename):
         with open(filename, 'r') as f:
              url = f.read()
          return url
      
      def writetopicurl(filename,url):
          try:
             with open(filename, 'w') as f:
                  f.write(url)
              return True
          except:
              return False   
      
      def getDownloadURL(file_id):
          file_url = 'https://api.zsxq.com/v1.10/files/{0}/download_url'.format(file_id)
          return file_url
      
      def get_topic_list(topics_url, end_time=None):
          if end_time:
              url = topics_url + '&end_time=' + quote(end_time)
          return url
      
      def get_endtime(create_time):
          try:
              # int -1 后需要進(jìn)行補(bǔ) 0 處理,test_str.zfill(3)
              end_time = create_time[:20]+str(int(create_time[20:23])-1).zfill(3)+create_time[23:]
              # 時(shí)間出現(xiàn)整點(diǎn)時(shí)需要特殊處理,否則會出現(xiàn) -1
              if create_time[20:23] == '000':
                  temp_time = datetime.datetime.strptime(create_time, "%Y-%m-%dT%H:%M:%S.%f+0800")
                  temp_time += datetime.timedelta(seconds=-1)
                  end_time = temp_time.strftime("%Y-%m-%dT%H:%M:%S") + '.999+0800'
                  print('end_time:{0}'.format(end_time))
              return end_time
          except IndexError :
              print("error")
              return None
      
      def request_topics_url(topics_url,headers):
          topics_page = requests.get(topics_url, headers=headers)
          if topics_page.status_code == 200:
              resp_data = json.loads(topics_page.text)
              return resp_data
          else:
              return None
      
      def download_file(index, url, file_name,filedir):
          currentpath=os.getcwd()
          if not os.path.exists(filedir):
              os.mkdir(filedir)
          file_fullpath = '{0}\{1}\{2}'.format(currentpath,filedir,file_name)
          if os.path.exists(file_fullpath):
              return True
          file_res = requests.get(url)
          #print('file_res.status_code:{0}'.format(file_res.status_code))
          if file_res.status_code == 200:
             with open(file_fullpath, 'wb') as f:
                  f.write(file_res.content)
                  print('----第 {0}個(gè)文件:{1}下載成功!'.format(index+1,file_name))
                  return True
      
          else:
              return False
      
      def download_file_url(url):
          doc = pq(requests.get(url,headers=headers).text)
          res_data = json.loads(doc('p').text()) 
          fileurl = res_data['resp_data']['download_url'] 
          return fileurl     
      
      if __name__ =="__main__":
          init_topics_url = 'https://api.zsxq.com/v1.10/groups/454548818428/files?count=20'
              #以下載老齊的讀書圈為例
          urlfile = 'temp_topics_url.txt'
          filedir = '讀書圈文件'
          if not os.path.exists(urlfile):
             writetopicurl(urlfile, init_topics_url)
              topic_urls = init_topics_url
          else:
              topic_urls = readtopicurl(urlfile)
      
          print('file_urls:{0}'.format(topic_urls))
      
         while True:
              resp_data = request_topics_url(topic_urls,headers)
              filelist = resp_data['resp_data']['files']
              for index , urlinfo in enumerate(filelist):
                  file_id = urlinfo['file']['file_id']
                  file_name = urlinfo['file']['name']
                  create_time = urlinfo['file']['create_time']
                  downloadurl = getDownloadURL(file_id)
                  file_url = download_file_url(downloadurl)
                  download_file(index,file_url, file_name,filedir)
                  if index == 19:
                      end_time = get_endtime(create_time)
                      topic_urls = get_topic_list(init_topics_url,end_time)
                     writetopicurl(urlfile, topic_urls)
                      print('topic_urls:{0}'.format(topic_urls))
                      #print('end_time:'.format(end_time))
              if len(filelist) < 20:
                  print('全部文件下載完成!!!')
                  break
      

      另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

      創(chuàng)新互聯(lián)公司致力于成都網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì),成都網(wǎng)站設(shè)計(jì),集團(tuán)網(wǎng)站建設(shè)等服務(wù)標(biāo)準(zhǔn)化,推過標(biāo)準(zhǔn)化降低中小企業(yè)的建站的成本,并持續(xù)提升建站的定制化服務(wù)水平進(jìn)行質(zhì)量交付,讓企業(yè)網(wǎng)站從市場競爭中脫穎而出。 選擇創(chuàng)新互聯(lián)公司,就選擇了安全、穩(wěn)定、美觀的網(wǎng)站建設(shè)服務(wù)!
      網(wǎng)頁題目:python知識星球文件下載-創(chuàng)新互聯(lián)
      本文來源:http://www.ef60e0e.cn/article/dpdicj.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        莲花县| 永修县| 治多县| 绥棱县| 嘉定区| 榆中县| 丹凤县| 四子王旗| 芮城县| 泸水县| 于田县| 临武县| 通榆县| 阳江市| 龙南县| 宣城市| 康保县| 原平市| 江门市| 柳州市| 盖州市| 剑阁县| 当阳市| 黄骅市| 寿光市| 新巴尔虎左旗| 灵石县| 汕尾市| 河东区| 大埔区| 睢宁县| 东莞市| 张家港市| 宁都县| 邓州市| 大安市| 周至县| 田东县| 襄汾县| 郓城县| 濮阳县|