Browse Source

勾选保存.txt文件后,.txt文件不再保存在程序安装目录下,将保存至输出文件夹

剑断了 2 years ago
parent
commit
baf46db861
1 changed files with 8 additions and 5 deletions
  1. 8 5
      TitleSpider.py

+ 8 - 5
TitleSpider.py

@@ -3,6 +3,7 @@
 # @Author : 刘正阳
 # @Author : 刘正阳
 # @File : TitleSpider.py
 # @File : TitleSpider.py
 # @Software : PyCharm
 # @Software : PyCharm
+import os
 
 
 import requests
 import requests
 import re
 import re
@@ -37,15 +38,17 @@ def FinData(url):
     return dataList, urlTitle
     return dataList, urlTitle
 
 
 
 
-def saveAsTxt(video_list, urlTitle):
+def saveAsTxt(video_list, urlTitle, path):
     fileTitle = urlTitle + ".txt"  # 合成.txt格式 文件名
     fileTitle = urlTitle + ".txt"  # 合成.txt格式 文件名
-
-    # 去除标题中的Windows不兼容的的命名字
     for s in fileTitle:
     for s in fileTitle:
         cut = ['|', '\\', '/', ':', '?', '"', '<', '>']
         cut = ['|', '\\', '/', ':', '?', '"', '<', '>']
         if s in cut:
         if s in cut:
             fileTitle = fileTitle.replace(s, ' ')
             fileTitle = fileTitle.replace(s, ' ')
 
 
+    fileTitle = os.path.join(path, fileTitle)
+    # 去除标题中的Windows不兼容的的命名字
+
+
     nameFile = open(fileTitle, "w", encoding="utf-8")  # 写入文件
     nameFile = open(fileTitle, "w", encoding="utf-8")  # 写入文件
     j = 0
     j = 0
     for i in video_list:
     for i in video_list:
@@ -55,7 +58,7 @@ def saveAsTxt(video_list, urlTitle):
     return fileTitle
     return fileTitle
 
 
 
 
-def GetTxt(bid):
+def GetTxt(bid, path):
     global fileName
     global fileName
     urlPart = 'https://www.bilibili.com/video/'
     urlPart = 'https://www.bilibili.com/video/'
     bv = bid
     bv = bid
@@ -63,4 +66,4 @@ def GetTxt(bid):
 
 
     dataList, urlTile = FinData(url)
     dataList, urlTile = FinData(url)
 
 
-    fileName = saveAsTxt(dataList, urlTile)
+    fileName = saveAsTxt(dataList, urlTile, path)