python - how to save the image locally from webpage -
how download image below link
https://www-nass.nhtsa.dot.gov/nass/cds/getbinary.aspx?sceneview&imageid=247572955&version=-1
the code tried
import urllib.request import sys import shutil imglink = "https://www-nass.nhtsa.dot.gov/nass/cds/getbinary.aspx?imageview&imageid=247247011&desc=front%2fleft+oblique&title=vehicle+1+-+frontleftoblique&version=0&extend=jpg" savelink = "c:/users/vm82958/desktop/nass_extract/abcd.jpg" if sys.version_info[0] < 3: urllib.urlopen(imglink) response, open(savelink, 'wb') out_file: shutil.copyfileobj(response, out_file) else: urllib.request.urlopen(imglink) response, open(savelink, 'wb') out_file: shutil.copyfileobj(response, out_file)
image not getting downloaded 1kb file downloaded.
any please
the response imglink
not image file rather html page displays image.
<script type="text/javascript"> function init() { document.getelementbyid("loading").src = "getbinary.aspx?image&imageid=247247011&caseid=&version=0"; document.getelementbyid("loading").onload = ";" } </script> <body> <table width="100%"> <tr><td align="center" style="font-size:large">images may not scale.</td></tr> <tr><td align="center">vehicle 1 - frontleftoblique</td></tr> <tr><td align="center">front/left oblique</td></tr> <tr><td align="center"><img onload="javascript:init();" id="loading" width="640px" heigth="480px" src="img/loading.gif"/></td></tr> <tr><td align="center">image id: 247247011</td></tr> <tr><td align="center"><a href='javascript:close()'>close</a></td></tr> </table> </body>
the actual url of image https://www-nass.nhtsa.dot.gov/nass/cds/getbinary.aspx?image&imageid=247247011&caseid=&version=0
javascript run , insert actual location of image img
tag you'll have use selenium , beautifulsoup parse html.
here's script download image (not using selenium though) can see way it.
import urllib import sys imglink = "https://www-nass.nhtsa.dot.gov/nass/cds/getbinary.aspx?image&imageid=247247011&caseid=&version=0" savelink = "c:/users/john/desktop/abcd.jpg" open(savelink, 'wb') out_file: response = urllib.urlopen(imglink) out_file.write(response.read())
Comments
Post a Comment