Click here to Skip to main content
15,906,816 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to get all the pictures off of /r/memes/ on reddit and store them in a folder.
when i run this code i get "line 10, in <module>
image_tags = soup.findALL('img')
TypeError: 'NoneType' object is not callable"

What I have tried:

import requests
from bs4 import BeautifulSoup as bs
import os

url = 'https://www.reddit.com/r/memes/'

page = requests.get(url)
soup = bs(page.text,'html.parser')

image_tags = soup.findALL('img')

if not os.path.exists('memes'):
    os.makedirs('memes')

os.chdir('memes')

x = 0

for image in image_tags:
    try:
        url = image['src']
        source = requests.get(url)
        if source.status_code == 200:
            with open('memes-' + str(x) + '.jpg', 'wb') as f:
                f.write(requests.get(url).content)
                f.close()
                x += 1
    except:
        pass
Posted
Updated 8-Sep-18 4:30am
v3

1 solution

Python
with open('memes-' + str(x) = '.jpg', 'wb') as f:

What is that = sign doing there?
 
Share this answer
 
Comments
Member 13915301 8-Sep-18 8:42am    
i forgot to press shift, but when i run it now i get "TypeError: 'NoneType' object is not callable"
Richard MacCutchan 8-Sep-18 9:21am    
Please update the question and show where the error occurs.
Member 13915301 8-Sep-18 10:31am    
i updated it
Richard MacCutchan 8-Sep-18 10:58am    
I can only assume that the previous line soup = bs(page.text,'html.parser') failed, so the soup object has no valid reference.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900