This Go program allows you to scrape and download images from a specified Reddit subreddit. It utilizes the Colly library for web scraping and makes the process faster and more efficient by using concurrency with goroutines.
- Scrapes Images from Reddit: Fetches image URLs from posts within a subreddit and downloads them.
- Concurrency: Uses Go's goroutines to download multiple images simultaneously, making the scraping process faster.
- Efficient: The program handles multiple pages within a subreddit, following the "next" button to continue scraping and downloading images.
- Customizable: You can specify any subreddit to scrape images from.
- Colly (
github.com/gocolly/colly) for web scraping. - Go standard libraries:
net/httpfor HTTP requests.iofor copying data to files.osfor file handling.strconv,strings, andsyncfor concurrency and data handling.
-
Install Dependencies: Install Colly by running:
go get github.com/gocolly/colly
-
Run the Program:
go run main.go
-
Enter Subreddit URL: The program will prompt you to enter a subreddit URL (e.g.,
golang,funny, etc.). -
Download Images: The program will automatically start scraping images from the specified subreddit and save them locally with filenames like
image1.jpg,image2.jpg, etc.
- The program uses goroutines to download images concurrently, which speeds up the scraping and downloading process.
- It ensures efficient image downloading by managing concurrency with sync.WaitGroup and sync.RWMutex.