python - how to download pics to a specific folder location on windows? -


i have script download images given web url address:

from selenium import webdriver import urllib   class chromefoxtest:      def __init__(self,url):         self.url=url         self.uri = []      def chrometest(self):        # file_name = "c:\users\administrator\downloads\images"         self.driver=webdriver.chrome()         self.driver.get(self.url)         self.r=self.driver.find_elements_by_tag_name('img')        # output=open(file_name,'w')          i, v in enumerate(self.r):             src = v.get_attribute("src")             self.uri.append(src)             pos = len(src) - src[::-1].index('/')             print src[pos:]             self.g=urllib.urlretrieve(src, src[pos:])           #  output.write(src)        # output.close()   if __name__=='__main__':     ft=chromefoxtest("http://imgur.com/")     ft.chrometest() 

my question is: how make script save pics specific folder location on windows machine?

you need specify path want save file. explained in the documentation urllib.urlretrieve:

the method is: urllib.urlretrieve(url[, filename[, reporthook[, data]]]). , documentation says:

the second argument, if present, specifies file location copy (if absent, location tempfile generated name).

so...

urllib.urlretrieve(src, 'location/on/my/system/foo.png') 

will save image specified folder.

also, consider reviewing documentation os.path. functions manipulate file names , paths.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -