Skip to content

the image doesn't download to a folder #29

@PrethamMuthappa

Description

@PrethamMuthappa

well the code doesn't do anything and it just shows 200,so i tried to modify the code so that the images get stored in a directory ,but still it doesn't work
``
import os
from bs4 import BeautifulSoup
import urllib.request
import requests

os.makedirs('images', exist_ok=True)

url = "https://www.reddit.com/r/BabyYoda"

response = requests.get(url)

if response.status_code != 200:
print(f"Status: {response.status_code} — Try rerunning the code\n")
else:
print(f"Status: {response.status_code}\n")

soup = BeautifulSoup(response.content, "html.parser")
for data in soup.find_all("img", attrs={"alt":"Post image"}):
ll=data.get('src')

imagdownload=requests.get(os.path.join('https://www.reddit.com/'),ll)
img=open(os.path.join('images',os.path.basename(ll),'wb'))
for down in imagdownload.iter_content(10000):
    img.write(down)

``
any idea what to do?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy