PermissionError : [Error 13] Permission denied : 'E:/图片'

When I used with open to download pictures, I encountered permission denied.

Insert picture description here
When I reviewed the code, when I was on Baidu, I didn't find out what happened, asked a friend, and finally solved it.

#这里是部分代码,然而,问题也就出现在这
tupian = strhtml_xpath.xpath("//center//img/@src")
for tu in tupian:
	with open(r'E:/图片','ab') as fp:
		print("正在下载...")
		fp.write(tu.content)

As shown in the figure, the tupian found, its value is a picture link, is a list (list), you want to continue to use requests to continue the request, use write ().
Just like:

tupian = strhtml_xpath.xpath("//center//img/@src")
for tu in tupian:
	#请求tu的链接
	t = requests.get(tu)
	#给图片起名
	titles = tu.split('/')[-1]
	#在下载图片时,要给图片起名,否则下载不了。
	with open(r"E:/图片/{}".format(titles),'ab') as fp:
	print("正在下载...{}".format(titles))
	fp.write(t.content)

to sum up:

When using with open to download pictures:

  1. After getting the list of URLs of the pictures, you must request the request before writing using the write () method.
  2. When downloading pictures, give them a name.
Published 26 original articles · praised 5 · visits 777

Guess you like

Origin blog.csdn.net/weixin_44730235/article/details/104723277