This question already has an answer here:
How to use urllib to download image from web
(1 answer)
Closed 7 years ago.
I use the following code to download the image 14112758275517_800X533.jpg.
The problem is that I cannot open the 14112758275517_800X533.jpg saved as G:\\image.jpg because the
Windows photo viewer was unable to open the picture, as the file may be corrupted, damaged or too large
import urllib
imageurl="http://img.vogue.com.cn/userfiles/201409/14112758275517_800X533.jpg"
pic_name = "G:\\image.jpg"
urllib.urlretrieve(imageurl, pic_name)
How can I download the image so that it is readable?
I think you cannot. It is likely a website problem, not something in the code you posted.
I am given a 403 Forbidden when trying to type the url you gave even with a navigator.
As an example, the following works and only the url has changed :
import urllib
imageurl="https://www.python.org/static/img/python-logo.png"
pic_name = "./image.png"
urllib.urlretrieve(imageurl, pic_name)
However, you might want to check other topics about the subjet as there are more advanced techniques to download images from the web such as https://stackoverflow.com/a/8389368/2549230
Related
How can we save the webpage including the content in it, so that it is viewable offline, using urllib in python language? Currently I am using the following code:
import urllib.request
driver.webdriver.Chrome()
driver.get("http://www.yahoo.com")
urllib.request.urlretrieve("http://www.yahoo.com", C:\\Users\\karanjuneja\\Downloads\\kj\\yahoo.mhtml")
This works and strores an mhtml version of the webpage in the folder, but when you open the file, you will only find the codes written and not the page how it appears online. Do we need to make changes to the code?
Also, is there an alternate way of saving the webpage in MHTML format with all the content as it appears online, and not just the source.Any suggestions?
Thanks Karan
I guess this site might help you~
Create an MHTML archive
This question already has an answer here:
Downloading Images from Google Drive
(1 answer)
Closed 6 years ago.
I have multiple google drive images url in the text file, I want to download each image from its url, Here catch is I want to download and save images to it's original name.
Here is the reference
Can anyone help me with the solution
Alternate Solution:
I have found out one solution to make it download images
Original URL:-
https://drive.google.com/open?id=0BwJzkr_gZEA0d1h2dTN6MndvdkE
Convert it to:-
https://drive.google.com/uc?export=download&id=0BwJzkr_gZEA0d1h2dTN6MndvdkE
After that add this url into IDM you will able to download image with original name.
Hope that will help.
Have you try to do it throught Google Drive API :
here to create a simple script and here for endpoints
This question already has answers here:
How to compose the URL for a reverse Google image search?
(3 answers)
Closed 3 years ago.
I'm searching a script for finding similar images to my local images. Actually, I have searched similar topic on stackoverflow but I could not find any solution or clue for my problem.
The topic which is in following url is similar to my problem but it searches with using texts.
python search with image google images
I think that I must pass my local images to my http request as raw bytes but I did not find how can I do that.
Finally, I tried to upload my local images to the web and search with using urls but this time I faced the following problem:
When I searched this image with its url, google generates this url:
https://www.google.com/search?tbs=sbi:AMhZZivZoXHOHzWl5_1BGnG05Bm1LpdXCjewepYnpAH4Xi-s7fVU0S86XG4MFlP7hYlGUpioWaZSjwBBIRDOXrGL8uum9wurfEZowKDUl_1GMPE8JHOO5vEb_1iMSbkmvqx-sWxbPqeHeW1eeJPDgtjio_1l7sJcvSbIquQOoacs3x1mDiF7OLw0mNA3WdR59dFDZAwlpU9A2cXbk_1RrqcilNOEcf0osSDx6TDtXN9ndN3ZSFF8NQhHVDPRrjqRpETbXpVHtyJiIxTzLeAiSC-POpwwN1I3tutScJISO72ZhLCUMAZ-gAuuaTHiHQq-vJBcAgq_1zfzwrDxncCVaKBlqb-zDHclm_1tc9qAMlIIsuKvGXnOSY9flVL4Nqk6Js8Un7_1P_1MbkgVCOcWRmbKG0E_1Sl_145Xe-las_18k4e0N0Ar9eKWGd5gvO33ai967E1tj8uiBqfjZTDYUC_1UARgU-IedUIU4uTmpLgK2xMBTXbSgLU8LdW5ZmB1p_1Tm7tpyIczoN23B2AJz9tFp1wnVOeCi_1jOcegCMPxw_1pULXDVWmgd_1f1OMX_1OrLl7wq5VZbBnH3ME62tdKCScZySq7_11Rx7zvzf2JTKQ_16jt_1HJ2Nf6mYb77n58TSMOSbxNvlCnT6afbPHN_101-Xrb2o0QnkESNBMKNwhLg2ZDDgRSgO0gvyzn86FAIR4Eif77PMV0IlEXtaizdveGwCN3upch2XZQpzljgMOUD0ZEfpe_1GxysMuetPZe_12MsYFp2EVW_19oFqTiavEtn2LIcBI1jhow5zWCkwmcNv8Dz80qYTLCRcAaj5l5w2DsdJd8IiufYP0qxKb5pwXbdM0k3-jEQVaWBo_1wK4dohn3UierX63up9YZWNfKNciTjecJ2q69b9xkhtXp_1LWt9Sdi8-xt25FS1XkW6VdVuqhX9-OexZ9G8bV1SgOEHx5GOuCkdsBjqBZ_1Df9wDGLKDX4V9BVvpX_13TLn6YNFtkHR70z_1zaG66rHPun-fWygzsO_1uSmJH5BtcQODEOSJ7jCs_1iSJf--RB339DBzLenbJB_1HUVPiC7Tj0BvbnWtLnY9sElHi5jPprOlqfVa9uQe21eymwXZROi4aWwhByeODCsCfZjjUNoi0M_1pCTva4KW6mlmrWshh9h_1_1kl3Wx7sKpHGBqIY7VJ8pG3kcp7x0YtbPmfxF6J2iKoMzKHyutTx3cn5PJY9kZhOYs5RCs9ejC0Vmw42qdQaivEUB1aQazxRYH-knaGcbANS0p2OacI32X1SrwWoOdodj733y5_1jJi2soZi4COkUjG_18_1c028sLlBkdVkedcq8DXbUEcQB5jIQPx1115aZqdn8SzSLGxLhowIlVxq6kLuyXuLJy72kArT91Rol2v5jHFxapFjrNuDgwdirVQQIsbx_1jXzgTVPdhYV08eFdpnVnsVu3OaUNZPZO8gsSs9A
I expected a url like google.com/search?url={image_url} but it isn't. Hence, I cannot generate a script for searching my local images.
How can I solve my problem? Thanks for your help.
Use the following url
https://www.google.com/searchbyimage?&image_url=
and concatenate your image URL to it.
This question already has answers here:
Python download a file
(2 answers)
Closed 9 years ago.
I am trying to use Python 2.7 to open a web browser and download and save a linked kml file.
The website is:
rmgsc.cr.usgs.gov/outgoing/GeoMAC/ActiveFirePerimeters.kml
When I run the code below, a new kml file appears to be saved on my drive, however it does not bring over the entire file. Instead of 154MB, it brings over a file that is only 17 bytes.
I can either go to the website (rmgsc.cr.usgs.gov/outgoing/GeoMAC/) and then click on a link named "ActiveFirePerimeters.kml", or go to the website with the kml file name included which automatically initiates a download. In IE9 I would then need to click a "Save" button, however in Chrome it appears to automatically download. However in both only 17bytes come across....
Here is my code for Internet Explorer:
import os, webbrowser
target_dir = r"C:\DataTest"
filename = "ActiveFirePerimeters.kml"
fullname = os.path.join(target_dir,filename)
with open(fullname,"w") as f:
f.write("<html>....</html>")
url = "rmgsc.cr.usgs.gov/outgoing/GeoMAC/ActiveFirePerimeters.kml"
webbrowser.open(url,True,True)
os.system("taskkill /F /IM iexplore.exe")
Are you required to use Internet Explorer for some reason to accomplish this task ? I would suggest taking a look at the urllib module : http://docs.python.org/library/urllib.html. In particular, you can download a resource easily using :
import urllib
urllib.urlretrieve(source_url, local_file_path)
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to download a file in python
I'm playing with Python for doing some crawling stuff. I do know there is urllib.urlopen("http://XXXX") That can help me to get the html for target website. However, The link to the original image in that webpage will usually make the image in the backup page unavailable. I am wondering is there a way that can also save the image in the local space, then we can read the full content on the website without internet connection. It's like back up the whole webpage, but I'm not sure is there any way to do that in Python. Also, if it can get rid of the advertisement stuff, it will be more awesome though. Thanks.
If you're looking to backup a single webpage, you're well on your way.
Since you mention crawling, if you want to backup an entire website, you'll need to do some real crawling and you'll need scrapy for that.
There are several ways of downloading files off the interwebs, just see these questions:
Python File Download
How to- download a file in python
Automate file download from http using python
Hope this helps