1. <strong id="7actg"></strong>
    2. <table id="7actg"></table>

    3. <address id="7actg"></address>
      <address id="7actg"></address>
      1. <object id="7actg"><tt id="7actg"></tt></object>

        我用 Python 寫(xiě)了一個(gè) PDF 轉(zhuǎn)換器!

        共 14394字,需瀏覽 29分鐘

         ·

        2021-04-19 14:53


        前言


        一、思路分析

        https://app.xunjiepdf.com

        二、我的代碼

        導(dǎo)入相關(guān)庫(kù):

        import time
        import requests

        定義PDF2Word類:

        class PDF2Word():
            def __init__(self):
                self.machineid = 'ccc052ee5200088b92342303c4ea9399'
                self.token = ''
                self.guid = ''
                self.keytag = ''
            
            def produceToken(self):
                url = 'https://app.xunjiepdf.com/api/producetoken'
                headers = {
                        'User-Agent''Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0',
                        'Accept''application/json, text/javascript, */*; q=0.01',
                        'Accept-Language''zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
                        'Content-Type''application/x-www-form-urlencoded; charset=UTF-8',
                        'X-Requested-With''XMLHttpRequest',
                        'Origin''https://app.xunjiepdf.com',
                        'Connection''keep-alive',
                        'Referer''https://app.xunjiepdf.com/pdf2word/',}
                data = {'machineid':self.machineid}
                res = requests.post(url,headers=headers,data=data)
                res_json = res.json()
                if res_json['code'] == 10000:
                    self.token = res_json['token']
                    self.guid = res_json['guid']
                    print('成功獲取token')
                    return True
                else:
                    return False
            
            def uploadPDF(self,filepath):
                filename = filepath.split('/')[-1]
                files = {'file': open(filepath,'rb')}
                url = 'https://app.xunjiepdf.com/api/Upload'
                headers = {
                        'User-Agent''Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0',
                        'Accept''*/*',
                        'Accept-Language''zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
                        'Content-Type''application/pdf',
                        'Origin''https://app.xunjiepdf.com',
                        'Connection''keep-alive',
                        'Referer''https://app.xunjiepdf.com/pdf2word/',}
                params = (
                        ('tasktype''pdf2word'),
                        ('phonenumber'''),
                        ('loginkey'''),
                        ('machineid', self.machineid),
                        ('token', self.token),
                        ('limitsize''2048'),
                        ('pdfname', filename),
                        ('queuekey', self.guid),
                        ('uploadtime'''),
                        ('filecount''1'),
                        ('fileindex''1'),
                        ('pagerange''all'),
                        ('picturequality'''),
                        ('outputfileextension''docx'),
                        ('picturerotate''0,undefined'),
                        ('filesequence''0,undefined'),
                        ('filepwd'''),
                        ('iconsize'''),
                        ('picturetoonepdf'''),
                        ('isshare''0'),
                        ('softname''pdfonlineconverter'),
                        ('softversion''V5.0'),
                        ('validpagescount''20'),
                        ('limituse''1'),
                        ('filespwdlist'''),
                        ('fileCountwater''1'),
                        ('languagefrom'''),
                        ('languageto'''),
                        ('cadverchose'''),
                        ('pictureforecolor'''),
                        ('picturebackcolor'''),
                        ('id''WU_FILE_1'),
                        ('name', filename),
                        ('type''application/pdf'),
                        ('lastModifiedDate'''),
                        ('size'''),)
                res= requests.post(url,headers=headers,params=params,files=files)
                res_json = res.json()
                if res_json['message'] == '上傳成功':
                    self.keytag = res_json['keytag']
                    print('成功上傳PDF')
                    return True
                else:
                    return False
                
            def progress(self):
                url = 'https://app.xunjiepdf.com/api/Progress'
                headers = {
                        'User-Agent''Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0',
                        'Accept''text/plain, */*; q=0.01',
                        'Accept-Language''zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
                        'Content-Type''application/x-www-form-urlencoded; charset=UTF-8',
                        'X-Requested-With''XMLHttpRequest',
                        'Origin''https://app.xunjiepdf.com',
                        'Connection''keep-alive',
                        'Referer''https://app.xunjiepdf.com/pdf2word/',}
                data = {
                      'tasktag': self.keytag,
                      'phonenumber''',
                      'loginkey''',
                      'limituse''1'}
                res= requests.post(url,headers=headers,data=data)
                res_json = res.json()
                if res_json['message'] == '處理成功':
                    print('PDF處理完成')
                    return True
                else:
                    print('PDF處理中')
                    return False
                
            def downloadWord(self,output):
                url = 'https://app.xunjiepdf.com/download/fileid/%s'%self.keytag
                res = requests.get(url)
                with open(output,'wb'as f:
                    f.write(res.content)
                    print('PDF下載成功("%s")'%output)
                    
            def convertPDF(self,filepath,outpath):
                filename = filepath.split('/')[-1]
                filename = filename.split('.')[0]+'.docx'
                self.produceToken()
                self.uploadPDF(filepath)
                while True:
                    res = self.progress()
                    if res == True:
                        break
                    time.sleep(1)
                self.downloadWord(outpath+filename)

        執(zhí)行主函數(shù):

        if __name__=='__main__':    
            pdf2word = PDF2Word()
            pdf2word.convertPDF('001.pdf','')

        瀏覽 42
        點(diǎn)贊
        評(píng)論
        收藏
        分享

        手機(jī)掃一掃分享

        分享
        舉報(bào)
        評(píng)論
        圖片
        表情
        推薦
        點(diǎn)贊
        評(píng)論
        收藏
        分享

        手機(jī)掃一掃分享

        分享
        舉報(bào)
        1. <strong id="7actg"></strong>
        2. <table id="7actg"></table>

        3. <address id="7actg"></address>
          <address id="7actg"></address>
          1. <object id="7actg"><tt id="7actg"></tt></object>
            娇妻被交换粗又大又硬动图 | 免费A级毛片 | 日韩毛片在线观看不卡AV | 国产又粗又硬又长又爽的视频 | 屁屁草草影视CCYYCOM人 | 黄色无码免费观看 | 欧美性爱视频免费观看大鸡巴操死我 | 美女色网 | 红桃精品91一区二区久 | 成人一区二区三区久久精品嫩草 |