程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python oserror: [errno 22] invalid argument error resolution

編輯:Python

Problem description

When crawling video data and saving it locally, an error is reported :OSError: [Errno 22] Invalid argument

OSError: [Errno 22] Invalid argument: ' practice / Wang Han and the great Dunhuang people | For thousands of years , All his life .mp4'

Solutions

This error is not reported when crawling other videos , After comparison, it is found that there is a problem with the video name : Calling open Function time , The file path contains characters |, Result in an error .

with open(video_path+'.mp4', 'wb') as fp: fp.write(video_data)

Problem solving

When crawling file names , Will symbol | Replace . It is deleted here .

name = new_tree.xpath('//*[@id="detailsbd"]/div[1]/div[2]/div/div[1]/h1/text()')[0]
name = name.replace("|","") # Put the in the file name “|” delete 

So the problem was solved .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved