Scrape selected images

Multi tool use
up vote
-2
down vote
favorite
I am writing a program to crawl images from a website and it shows the list of images present in the website. The user can select which images to save from the given list. If I try to download all the images, there is no problem. But, when I select some images and try to download it, it cannot be viewed.
def fetch_url():
url = _url.get()
config['images'] =
_images.set(())
try:
page = requests.get(url)
except requests.RequestException as rex:
_sb(str(rex))
else:
soup = BeautifulSoup(page.content, 'html.parser')
images = fetch_images(soup, url)
if images:
_images.set(tuple(img['name'] for img in images))
_sb('Images found: {}'.format(len(images)))
else:
_sb('No images found!.')
config['images'] = images
def fetch_images(soup, base_url):
images =
for img in soup.findAll('img'):
src = img.get('src')
img_url = ('{base_url}/{src}'.format(base_url=base_url, src=src))
name = img_url.split('/')[-1]
if name[-3:] == "png" or name[-3:] == "jpg" or name[-4:] == "jpeg": ### <- here
images.append(dict(name=name, url=img_url))
return images
def fetch_selected_images(event):
widget = event.widget
selected_idx = widget.curselection()
selected_items = [widget.get(int(item)) for item in selected_idx]
selected_images =
url = _url.get() + '/img'
for img in selected_items:
img_url = ('{base_url}/{src}'.format(base_url=url, src=img))
name = img_url.split('/')[-1]
if name in selected_items:
selected_images.append(dict(name=name, url=img_url))
for idx in selected_idx:
widget.itemconfig(idx, fg='red')
config['images'] = selected_images
python web-scraping beautifulsoup
New contributor
Samrat Shrestha is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
-2
down vote
favorite
I am writing a program to crawl images from a website and it shows the list of images present in the website. The user can select which images to save from the given list. If I try to download all the images, there is no problem. But, when I select some images and try to download it, it cannot be viewed.
def fetch_url():
url = _url.get()
config['images'] =
_images.set(())
try:
page = requests.get(url)
except requests.RequestException as rex:
_sb(str(rex))
else:
soup = BeautifulSoup(page.content, 'html.parser')
images = fetch_images(soup, url)
if images:
_images.set(tuple(img['name'] for img in images))
_sb('Images found: {}'.format(len(images)))
else:
_sb('No images found!.')
config['images'] = images
def fetch_images(soup, base_url):
images =
for img in soup.findAll('img'):
src = img.get('src')
img_url = ('{base_url}/{src}'.format(base_url=base_url, src=src))
name = img_url.split('/')[-1]
if name[-3:] == "png" or name[-3:] == "jpg" or name[-4:] == "jpeg": ### <- here
images.append(dict(name=name, url=img_url))
return images
def fetch_selected_images(event):
widget = event.widget
selected_idx = widget.curselection()
selected_items = [widget.get(int(item)) for item in selected_idx]
selected_images =
url = _url.get() + '/img'
for img in selected_items:
img_url = ('{base_url}/{src}'.format(base_url=url, src=img))
name = img_url.split('/')[-1]
if name in selected_items:
selected_images.append(dict(name=name, url=img_url))
for idx in selected_idx:
widget.itemconfig(idx, fg='red')
config['images'] = selected_images
python web-scraping beautifulsoup
New contributor
Samrat Shrestha is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
I am writing a program to crawl images from a website and it shows the list of images present in the website. The user can select which images to save from the given list. If I try to download all the images, there is no problem. But, when I select some images and try to download it, it cannot be viewed.
def fetch_url():
url = _url.get()
config['images'] =
_images.set(())
try:
page = requests.get(url)
except requests.RequestException as rex:
_sb(str(rex))
else:
soup = BeautifulSoup(page.content, 'html.parser')
images = fetch_images(soup, url)
if images:
_images.set(tuple(img['name'] for img in images))
_sb('Images found: {}'.format(len(images)))
else:
_sb('No images found!.')
config['images'] = images
def fetch_images(soup, base_url):
images =
for img in soup.findAll('img'):
src = img.get('src')
img_url = ('{base_url}/{src}'.format(base_url=base_url, src=src))
name = img_url.split('/')[-1]
if name[-3:] == "png" or name[-3:] == "jpg" or name[-4:] == "jpeg": ### <- here
images.append(dict(name=name, url=img_url))
return images
def fetch_selected_images(event):
widget = event.widget
selected_idx = widget.curselection()
selected_items = [widget.get(int(item)) for item in selected_idx]
selected_images =
url = _url.get() + '/img'
for img in selected_items:
img_url = ('{base_url}/{src}'.format(base_url=url, src=img))
name = img_url.split('/')[-1]
if name in selected_items:
selected_images.append(dict(name=name, url=img_url))
for idx in selected_idx:
widget.itemconfig(idx, fg='red')
config['images'] = selected_images
python web-scraping beautifulsoup
New contributor
Samrat Shrestha is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I am writing a program to crawl images from a website and it shows the list of images present in the website. The user can select which images to save from the given list. If I try to download all the images, there is no problem. But, when I select some images and try to download it, it cannot be viewed.
def fetch_url():
url = _url.get()
config['images'] =
_images.set(())
try:
page = requests.get(url)
except requests.RequestException as rex:
_sb(str(rex))
else:
soup = BeautifulSoup(page.content, 'html.parser')
images = fetch_images(soup, url)
if images:
_images.set(tuple(img['name'] for img in images))
_sb('Images found: {}'.format(len(images)))
else:
_sb('No images found!.')
config['images'] = images
def fetch_images(soup, base_url):
images =
for img in soup.findAll('img'):
src = img.get('src')
img_url = ('{base_url}/{src}'.format(base_url=base_url, src=src))
name = img_url.split('/')[-1]
if name[-3:] == "png" or name[-3:] == "jpg" or name[-4:] == "jpeg": ### <- here
images.append(dict(name=name, url=img_url))
return images
def fetch_selected_images(event):
widget = event.widget
selected_idx = widget.curselection()
selected_items = [widget.get(int(item)) for item in selected_idx]
selected_images =
url = _url.get() + '/img'
for img in selected_items:
img_url = ('{base_url}/{src}'.format(base_url=url, src=img))
name = img_url.split('/')[-1]
if name in selected_items:
selected_images.append(dict(name=name, url=img_url))
for idx in selected_idx:
widget.itemconfig(idx, fg='red')
config['images'] = selected_images
python web-scraping beautifulsoup
python web-scraping beautifulsoup
New contributor
Samrat Shrestha is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Samrat Shrestha is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 14 hours ago
stranac
12.9k21723
12.9k21723
New contributor
Samrat Shrestha is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 16 hours ago
Samrat Shrestha
166
166
New contributor
Samrat Shrestha is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Samrat Shrestha is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Samrat Shrestha is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Samrat Shrestha is a new contributor. Be nice, and check out our Code of Conduct.
Samrat Shrestha is a new contributor. Be nice, and check out our Code of Conduct.
Samrat Shrestha is a new contributor. Be nice, and check out our Code of Conduct.
Samrat Shrestha is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53348833%2fscrape-selected-images%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
uljcDA1AZlYcoR JN9 UEwbMPhMyKY9Zx,QiAWpzf 389iSAywMy1IWQR02ia8