Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- console.log("Disclaimer: some websites may take some time to load and parse so please be patient, all websites tested so far work")
- const readline = require('readline').createInterface({
- input: process.stdin,
- output: process.stdout
- });
- const jsdom = require("jsdom");
- const { stringify } = require('querystring');
- var raw = ""
- var tables = ""
- var links1 = []
- var lmfaooo = []
- var path = []
- const request = require('request');
- const { getSystemErrorMap } = require('util');
- function getstuff(link) {
- request(link, function (error, response, body) {
- raw = body
- var doc = new jsdom.JSDOM(raw);
- tables = doc.window.document.getElementsByTagName("table")
- for (let i = 0; i < tables.length; i++) {
- tables[i].innerHTML = ""
- }
- raw = doc.window.document.documentElement.outerHTML
- raw = raw.substring(raw.indexOf("firstHeading"))
- raw = raw.substring(raw.indexOf("<p>"))
- raw = raw.substring(0,raw.indexOf("<h2>"))
- doc = new jsdom.JSDOM(raw);
- var links = doc.window.document.getElementsByTagName("a")
- for (let i = 0;i<links.length;i++){
- links1[i] = links[i].getAttribute("href")
- links[i].setAttribute("href", i)
- }
- raw = doc.window.document.documentElement.outerHTML
- raw = raw.replace(/ *\([^)]*\) */g, "")
- raw = restorelinks(raw)
- raw = raw.substring(raw.indexOf('a href="/wiki/') + 14)
- raw = raw.substring(0, raw.indexOf('"'))
- console.log(raw)
- if (path.indexOf(raw)!=-1){
- console.log("Loop detected, looped back to "+raw+", path to philosophy not found")
- return;
- }
- path.push(raw)
- if (raw != "Philosophy") {
- getstuff("https://en.wikipedia.org/wiki/" + raw)
- }
- else {
- lmfaooo = path
- }
- })
- return lmfaooo
- }
- function restorelinks(bruh){
- var pos = 0
- while (bruh.indexOf("a href", pos)!=-1){
- bruh = bruh.substring(0,bruh.indexOf('a href="', pos)+8)+links1[parseInt(bruh.substring(bruh.indexOf('a href="', pos)+8,bruh.indexOf('"',bruh.indexOf('a href="', pos)+8)))]+bruh.substring(bruh.indexOf('"',bruh.indexOf('a href="', pos)+8))
- pos = bruh.indexOf("a href", pos)+7
- }
- return bruh
- }
- readline.question(`Do you want to enter a link to a wikipedia page?`, name => {
- if (name.toLowerCase() == "yes") {
- readline.question(`Please enter your link:`, g => {
- getstuff(g)
- readline.close()
- })
- } else {
- readline.question(`Would you like to start from a random page?`, name1 => {
- if (name1.toLowerCase() == "yes") {
- getstuff("https://en.wikipedia.org/wiki/Special:Random")
- readline.close()
- }
- else {
- readline.question(`Would you like to display the longest length from 25 pages?(they run at the same time)`, name2 => {
- if (name2.toLowerCase() == "yes") {
- var max = ["g"]
- var s = ["s"]
- for (let i = 0;i<25;i++){
- s = getstuff("https://en.wikipedia.org/wiki/Special:Random")
- if (max.length<s.length){
- max = s
- }
- }
- console.log("The longest path was:"+max)
- readline.close()
- }
- else {
- console.log("sorry!")
- readline.close()
- }
- })
- }
- })
- }
- })
Advertisement
Add Comment
Please, Sign In to add comment