Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/bash
- # Usage: ./RedditTextScraper.sh <subreddit (Caps sensitive!)> <time (day, week, month, year or all)> <number of posts to download>
- # Example: ./RedditTextScraper.sh DataHoarder month 20
- # Downloads the given subreddit and take parameters for time and number of posts.
- wget -e robots=off -p -k -r --level=1 -I /r/$1/comments https://www.reddit.com/r/$1/top/\?sort\=top\&t\=$2\&limit\=$3
- # Removes the string "data-inbound-url" from the main html file because it interferes with the ability to open comment pages
- sed -e s/data-inbound-url\=//g -i ./www.reddit.com/r/$1/top/index.html\?\sort\=\top\&t\=$2\&limit\=$3
- # Fixes paths to comment page html files so that it can be copied to the script's directory
- sed -i 's/href\=\"\.\.\//href\=\"www.reddit.com\/r\/'$1'\//g' -i ./www.reddit.com/r/$1/top/index.html\?\sort\=\top\&t\=$2\&limit\=$3
- #Setting variable for the subsequent filename
- fulldate="$(date +%m-%d-%y)"
- # Copies the main html file to a file in the script's directory for easier access
- cp ./www.reddit.com/r/$1/top/index.html\?\sort\=\top\&t\=$2\&limit\=$3 $1" - Top "$3" from "$2" - "$fulldate".html"
Add Comment
Please, Sign In to add comment