There is an image on a webpage which I would like to save on my disk using python. What I tried to do was
r=requests.get(url, timeout=60)
p=os.path.sep.join([args["output"],"{}.jpeg".format(str(total).zfill(5))])
f.write(r.content)
f.close()
But I realized that the file saved is not in image format as
$file name_of_file
00018.jpeg: HTML document, ASCII text, with very long lines, with no line terminators
Then I tried to:
r=requests.get(url, timeout=60)
p=os.path.sep.join([args["output"],"{}.jpeg".format(str(total).zfill(5))])
f=open(p, "wb")
i=r.raw
q=Image.open(BytesIO(r.content))
print(q.type)
f.write(i)
f.close()
But with no success. What should I do?
UPDATE:
r = requests.get(url, timeout=60)
# save the image to disk
p = os.path.sep.join([args["output"], "{}.jpeg".format(
str(total).zfill(5))])
with open("test.jpeg","wb+") as f:
f.write(requests.get("name_of_website",headers=headers).content)
f.close()
When I copied the image manually from the web using cursor, it was a jpg format.