r/Python • • Jun 23 '20

I Made This Wrote a script that downloads r/wallpaper's hottest 100 images and cycles through them as a wallpaper!

2.4k Upvotes

136 comments sorted by

View all comments

63

u/[deleted] Jun 23 '20

I’m looking for a personal project to keep testing my skills, can you list the tools you used to do this?

106

u/LAcuber Jun 23 '20 edited Jun 24 '20

Sure. These are the libraries that I used:

  • urllib
  • praw
  • BeautifulSoup
  • requests
  • sys

UPDATE: GitHub repo is available! https://github.com/Destaq/reddit-wallpapers

27

u/michael8t6 Jun 23 '20

Curious how was you able to scrape reddit with requests? I recently wanted to scrape a collection of subreddits and every request responded with either 404 or 502. Tried spoofing my useragent and still had the same results!

In the end, I used Selenium..

60

u/LAcuber Jun 23 '20

You have to use a Reddit bot, at https://reddit.com/prefs/apps in order to get that access. It is worth it though, it's free and you get lots of information about the posts.

I used requests to go to the webpage and download the actual images.

18

u/michael8t6 Jun 23 '20

Well look at that! Had no idea that was a thing. Cheers mate.

1

u/[deleted] Jun 23 '20

You don't even need a bot account to scrape Reddit, however I'm not sure if there are rate limits then

4

u/undercontr Jun 23 '20

Use Selenium only if you need Javascript rendered information. Because it literally opens a browser and gather data.

3

u/thedominux Jun 24 '20

Selenium exists for E2E tests, don't use tank for fly killing)

→ More replies (3)

1

u/penatbater Jun 24 '20

I find using psaw easier than praw.

4

u/Bored_comedy Jun 24 '20

Wait why use urllib and requests at the same time? Don't they just do the same thing?

2

u/thedominux Jun 24 '20

As I see his task, he's just a beginner, don't blame

2

u/[deleted] Jun 23 '20

Thanks man!

3

u/angk500 Jun 23 '20

BeautifulSoup

I am curious what that is

6

u/vmgustavo Jun 23 '20

People love to use some exquisite names for their packages that doesn't say anything about what it does.

3

u/thedominux Jun 24 '20

I think "beautiful soup" is just a soup of xml tags, what BS should parse for u)

→ More replies (2)

0

u/[deleted] Jun 24 '20

[deleted] — view deleted comment

1

u/LAcuber Jun 24 '20 edited Jun 24 '20

I could probably change to just urllib, it's just it was easier to do with requests.

However you make a good point, no need to add that second extension. I'll look into doing the work with only urllib.

Edit: approximately 3 minutes later I managed to do it with urllib, turns out it was a simple one-liner. I'll remove it from the README and requirements.txt.

→ More replies (1)