Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the image doesn't download to a folder #29

Open
PrethamMuthappa opened this issue Oct 22, 2022 · 0 comments
Open

the image doesn't download to a folder #29

PrethamMuthappa opened this issue Oct 22, 2022 · 0 comments

Comments

@PrethamMuthappa
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant