2019年7月

简介

19年雷佳音、易烊千玺主演的电视剧
《长安十二时辰》是由曹盾执导,雷佳音、易烊千玺领衔主演的古装悬疑剧。
该剧改编自马伯庸的同名小说,讲述了唐朝上元节前夕,长安城陷入危局,长安死囚张小敬临危受命,与李必携手在十二时辰内拯救长安的故事。
该剧于2019年6月27日在优酷视频播出

看原版小说

  • 链接 https://www.luoxia.com/shiershichen/
  • 代码

    # coding:utf-8
    
    # desc: 落霞小说网 爬小说
    # https://www.luoxia.com/shiershichen/
    
    import requests
    from lxml import etree
    
    s = requests.Session()
    s.keep_alive = False
    
    def getHtml(url):
      r = s.get(url,headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.80 Safari/537.36'})
      #print(r.text)
      html = etree.HTML(r.text)
      urls_text = html.xpath("//div[@id='content-list']/div/ul/li/a/text()")
      urls = html.xpath("//div[@id='content-list']/div/ul/li/a/@href")
      return urls,urls_text
    
    def getContent(url,filename):
      r = s.get(url,headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.80 Safari/537.36','referer': 'https://www.luoxia.com/shiershichen'})
      # print(r.text)
      html = etree.HTML(r.text)
      contents = html.xpath("//div[@id='nr1']/p/text()")
      with open(filename,'a', encoding='utf-8') as f:
          for x in contents:
              f.write(x + '\n')
    
    if __name__ == "__main__":
      url = "https://www.luoxia.com/shiershichen/"
      muluhtml = getHtml(url)
      filename ='长安十二时辰.txt'
      for x in range(len(muluhtml[0])):
          with open(filename,'a', encoding='utf-8') as f:
              f.write('\n' + muluhtml[1][x] + '\n')
          getContent(muluhtml[0][x],filename)
          print("正在抓取 长安十二时辰 %s , 章节名是 %s " % (muluhtml[0][x],muluhtml[1][x]))
  • 效果

需求

  • 把同个目录下的word文档都转换成pdf文档
  • 保存到同个目录下的同名文件

代码如下

  • Win10 + Office 2019 测试通过

    Sub Sava2PDF()
    '定义对话框变量
    Dim fd As FileDialog
    Set fd = Application.FileDialog(msoFileDialogFilePicker)
    
    Dim BaseFileName As String
    Dim FileNameArray() As String
    
    With fd
          If .Show = -1 Then
              '定义单个文件变量
              Dim vrtSelectedItem As Variant
               
              '定义循环变量
              Dim i As Integer
              i = 1
               
              '开始文件检索
              For Each vrtSelectedItem In .SelectedItems
    
                  '打开要转换为PDF的word文件
                  Dim tempDC As Document
                  Set tempDC = Documents.Open(vrtSelectedItem)
                  FileNameArray = Split(tempDC.Name, ".")
                  BaseFileName = FileNameArray(0)
                  'MsgBox (BaseFileName)
                  
                  tempDC.ExportAsFixedFormat OutputFileName:= _
                  tempDC.Path + "\" + BaseFileName + ".pdf", ExportFormat:=wdExportFormatPDF, _
                  OpenAfterExport:=False, OptimizeFor:=wdExportOptimizeForPrint, Range:= _
                  wdExportAllDocument, From:=1, To:=1, Item:=wdExportDocumentContent, _
                  IncludeDocProps:=True, KeepIRM:=True, CreateBookmarks:= _
                  wdExportCreateNoBookmarks, DocStructureTags:=True, BitmapMissingFonts:= _
                  True, UseISO19005_1:=False
                  tempDC.Close
          
              Next vrtSelectedItem
          End If
      End With
       
      Set fd = Nothing
    
    
    
    End Sub

成果

ffmpeg 从视频中提取音频文件保存为MP3

ffmpeg -i apple.mp4 -f mp3 -vn apple.mp3

ffmpeg 从视频中提取音频文件,修改播放速度

ffmpeg -i apple.mp4 -filter:a "atempo=1.3" -f mp3 -vn apple.mp3

注意:

  • 倍率调整范围为[0.5, 2.0]
#coding:utf-8
#description: MP42mp3

import os,sys
import argparse
import subprocess

def convert(path):
    bin = "ffmpeg.exe"
    ls = os.listdir(path)
    for x in ls:
        if x.endswith("mp4"):
            cmdargs = '%s -i "%s" -filter:a "atempo=1.3" -f mp3 -vn "%s"' % (bin ,x,x.replace(".mp4",".mp3"))
            print cmdargs

if __name__ =="__main__":
    if ( os.path.isdir(sys.argv[1])):
        path = sys.argv[1]
        convert(path)

参考链接:https://blog.csdn.net/matrix_laboratory/article/details/53158307