if ".jpg" in link or ".png" in link:
fd = urllib.request.urlopen(link)
#Checks the dimensions of said image file
Image_file = io.BytesIO(fd.read())
with Image.open(Image_file) as im:
width, height = im.size
print(im.size)
好的,所以我正在创建一个网络爬虫,它应该下载 1920 x 1080 大小的图像。实际的程序可以工作,但是 PyCharm 和 Codacy 说这里没有使用宽度和高度变量:
with Image.open(Image_file) as im:
width, height = im.size
我想这是对的,因为我稍后不会在代码中调用它们,但我想知道是否还有其他方法可以做到这一点,所以在查看代码时我没有看到未使用的代码错误。
另一个例子:
with Image.open(Image_file) as im:
width, height = im.size
#If the dimensions are 1920 by 1080, it will download the file in Wallpapers/filename_#WALL_#PAGE
#This format makes it easy to check which images was downloaded from which page
if(im.size == (1920, 1080)):
wall += 1
print("***FOUND***\t" + str(wall))
urllib.request.urlretrieve(link, "Wallpapers/filename"+ str(wall) +"_" + str(page) +".png")
可能是一个愚蠢的问题,但我感谢所有答案。:)