Page 1 of 1

Help for python download path

Posted: Fri Apr 18, 2014 8:21 pm
by senna99
I use this version of python ,where I need to type C:\New folder for download path?
I need this for my skin,to always have fresh photos from web.

Best Regards


# imageDownloader.py
# Finds and downloads all images from any given URL.
# FB - 201009083
import urllib2
from os.path import basename
from urlparse import urlsplit
from BeautifulSoup import BeautifulSoup # for HTML parsing

url = "http://www.yahoo.com"
urlContent = urllib2.urlopen(url).read()
soup = BeautifulSoup(''.join(urlContent))
imgTags = soup.findAll('img') # find all image tags

# download all images
for imgTag in imgTags:
imgUrl = imgTag['src']
try:

imgData = urllib2.urlopen(imgUrl).read()
fileName = basename(urlsplit(imgUrl)[2])
output = open(fileName,'wb')
output.write(imgData)
output.close()
except:
pass

Help for python download path

Posted: Fri Apr 18, 2014 8:50 pm
by Dom DXecutioner
Quick response as it's hard to post code from a phone... :)

Code: Select all

# set script id, which is the name of the script
SCRIPT_ID = "ImageDownloader"
# set the base directory for saving, which is the script data folder for the current user
BASE_FOLDER = xbmc.translatePath(special://profile/script_data/"


# your code...
...
# create folder path
FilePath = os.path.join(BASE_FOLDER, SCRIPT_ID)

# test directories exist, otherwise make them
If not os.path.exists(FilePath):
     os.makedirs(FilePath)

# put the path together
FileNameAndPath = os.path.join(FilePath, fileName)

# the rest of your code
...
Untested of course, but that's the basic idea...

Re: Help for python download path

Posted: Fri Apr 18, 2014 10:40 pm
by senna99
Thank you for your reply Dom

Unfortunately I have no knowledge as you,I've been trying to use your codes from xbox.gamertag.py but without success.
If you can help me please write me how to be looked to the whole structure .py with your and my codes together.
Thank you in advance

Best Regards

Help for python download path

Posted: Fri Apr 18, 2014 11:09 pm
by Dom DXecutioner
That's out of the scope of your original post

Re: Help for python download path

Posted: Sat Apr 19, 2014 6:57 am
by senna99
Hello Dom

I got the message,I will try to write the rest of the codes.
But thank you for the first posts,I will try to use these codes.

Best Regards