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'
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)
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 .