如何使用python爬蟲實現(xiàn)網(wǎng)頁視頻自動下載并保存:
-
使用python爬取頁面,然后自動下載視頻,但是這樣會有一個問題,我并不是需要所有視頻,有些是垃圾視頻不需要下載,python似乎還沒法做到識別我對哪些視頻是有價值的,所以這一步人工繞不開,我選擇直接把目標視頻的詳情頁直接右鍵另存為本地html文件,隨后再用python批量處理這些本地的html文件。
-
解析html文件取出視頻的標題和下載url,按格式存為本地json
-
讀取json,循環(huán)下載整個list的視頻,并按配置給視頻命名
目標功能點
-
遞歸讀取html列表
-
研究html內(nèi)格式、解密url
-
保存解析產(chǎn)物為json
-
讀取json下載保存視頻文章來源:http://www.zghlxwxcb.cn/news/detail-670406.html
功能點代碼????
這一步可以將每一個html文件的路徑從Downloads文件夾取出來。文章來源地址http://www.zghlxwxcb.cn/news/detail-670406.html
def get_all_path():
global train_path, all_path, labels
train_path, all_path, labels = "./Downloads", [], []
# 遞歸獲取文件夾內(nèi)文件列表
def get_label_and_wav(path, file):
dirs = os.listdir(path)
for a in dirs:
# print(a)
# # 是否為文件夾
# print(os.path.isfile(path + "/" + a))
if os.path.isfile(path + "/" + a):
all_path.append(dirs)
if file != "":
labels.append(file)
else:
get_label_and_wav(str(path) + "/" + str(a), a)
# 循環(huán)遍歷這個文件夾
return all_path, labels
到了這里,關(guān)于【python學習筆記】:實現(xiàn)網(wǎng)頁視頻自動下載并保存的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!