I have some files that contain one URL per line, like
....
I try to code for:
import wget
with open ("5074_url.txt", encoding='utf-8', mode = 'r') as f:
for line in list(f): # OR f.readlines()
filename = wget.download(line)
print (filename)
but raise Error msg:
Traceback (most recent call last):
File ".\Geturl2.py\", line 33, in <module>
filename = wget.download(line)
File "C:\Program Files (x86)\Python\lib\site-packages\wget.py", line 506, in download
(fd, tmpfile) = tempfile.mkstemp(".tmp", prefix=prefix, dir=".")
File "C:\Program Files (x86)\Python\lib\tempfile.py", line 342, in mkstemp
return _mkstemp_inner(dir, prefix, suffix, flags, output_type)
File "C:\Program Files (x86)\Python\lib\tempfile.py", line 260, in _mkstemp_inner
fd = _os.open(file, flags, 0o600)
OSError: [Errno 22] Invalid argument: '.\\page-1.jpg\ngjf6wrvy.tmp'
\ngjf6wrvy.tmp What's this ? There's no this in file, I'm sure that.
I'm using Python 3.6.5 on windows 10
I know it could use urllib.request.urlretrieve(url, filename)
,
but it has filename option. I don't wanna change filename.
So How don't change filename ?
[Solved]
import wget
with open ("5074_url.txt", encoding='utf-8', mode = 'r') as f:
for url in f.readlines():
filename = wget.download(url.strip())
print (filename)
Thank you so much for help !!!