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