Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "use strict";
- // Modules
- var request = require("request");
- var readline = require("readline");
- var os = require("os");
- var fs = require("fs-extra");
- var Crawler = require("crawler");
- var url = require("url");
- var Promise = require("bluebird");
- // Constant
- const rl = readline.createInterface({
- input: process.stdin,
- output: process.stdout
- });
- const redditUrl = "https://www.reddit.com/user/";
- // Variables
- var usernameUrl = "";
- var keywords = [];
- var searchedArray = [];
- console.log("Reddit profile scraper... case insensitive and search is based off space delimeter (typos will not appear in filter)");
- // Crawler
- var c = new Crawler({
- maxConnections: 10,
- callback: function(error, result, $) {
- new Promise(function(resolve, reject) {
- $("a.title").each(function(index, a) {
- for (var i = 0; i < keywords.length; i++) {
- if ($(a).text().toLowerCase().search(new RegExp("(^| )" + keywords[i] +"(?![^\\W])")) !== -1) {
- searchedArray.push({
- "url": $(a).attr("href"),
- "matchType": "Title",
- "matchContent": $(a).text()
- });
- }
- }
- });
- $(".usertext-body").each(function(index, a) {
- for (var i = 0; i < keywords.length; i++) {
- if ($(a).text().toLowerCase().search(new RegExp("(^| )" + keywords[i] +"(?![^\\W])")) !== -1) {
- searchedArray.push({
- "url": $(a).parent().parent().parent().find(".title").attr("href"),
- "matchType": "Comment",
- "matchContent": $(a).text()
- });
- }
- }
- });
- for (var i = 0; i < searchedArray.length; i++) {
- console.log("URL: " + searchedArray[i].url);
- console.log("MatchType: " + searchedArray[i].matchType);
- console.log("Content: " + searchedArray[i].matchContent);
- }
- searchedArray = [];
- resolve($(".next-button a").attr("href"));
- }).then(function(url){
- c.queue(url);
- });
- }
- });
- function askQuestion() {
- searchedArray = [];
- rl.question("Search username: ", function(usernameInput) {
- if (usernameInput) {
- usernameUrl = redditUrl + usernameInput;
- rl.question("Search keywords separated by comma: ", function(keywordsInput) {
- if (keywords) {
- keywords = keywordsInput.split(",");
- console.log("Starting to search " + usernameInput + "...");
- c.queue(usernameUrl);
- } else process.exit(1);
- });
- } else process.exit(1);
- });
- }
- askQuestion();
Add Comment
Please, Sign In to add comment