Scrape selected images











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









share|improve this question









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.
























    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









    share|improve this question









    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.






















      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









      share|improve this question









      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






      share|improve this question









      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.











      share|improve this question









      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.









      share|improve this question




      share|improve this question








      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.





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          Samrat Shrestha is a new contributor. Be nice, and check out our Code of Conduct.










           

          draft saved


          draft discarded


















          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






























          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.










           

          draft saved


          draft discarded


















          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.















           


          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Costa Masnaga

          Fotorealismo

          Sidney Franklin