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
- Dom DXecutioner
- Posts: 585
- Joined: Thu Jul 05, 2012 11:59 pm
- Location: California
- Has thanked: 249 times
- Been thanked: 219 times
- Contact:
Help for python download path
Quick response as it's hard to post code from a phone...
Untested of course, but that's the basic idea...
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
...
Re: Help for python download path
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
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
- Dom DXecutioner
- Posts: 585
- Joined: Thu Jul 05, 2012 11:59 pm
- Location: California
- Has thanked: 249 times
- Been thanked: 219 times
- Contact:
Re: Help for python download path
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
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