Created
January 19, 2019 19:55
-
-
Save PabloWestphalen/c7e04d7654493ddf3c5c86a96395a0c1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(async function() { | |
let torrents = []; | |
let q = prompt("Search: "); | |
let dest = 'https://1337x.to/search/' + q; | |
let searchPage = await getDom(dest + '/1/'); | |
let totalPages = parseInt( searchPage.querySelector('.pagination .last a').href.match(/\/(\d+)\/$/)[1] ); | |
for(let i = 1; i <= totalPages; i++) { | |
console.log("Reading ", `${dest}/${i}/`); | |
let html = await getDom(`${dest}/${i}/`); | |
console.log('got this html: ', html); | |
html.innerHTML = html; | |
torrents = [...torrents, [...html.querySelectorAll('.table-list tbody tr')].map( row => { | |
return { | |
title: row.querySelector('.name').textContent, | |
url: [...row.querySelectorAll('.name a')].slice(-1).pop().href, | |
seeds: parseInt( row.querySelector('.seeds').textContent ), | |
leeches: parseInt( row.querySelector('.leeches').textContent ) | |
}; | |
})]; | |
} | |
torrents = [].concat(...torrents); | |
console.log(torrents); | |
async function getDom(url) { | |
let html = await (await fetch(url)).text(); | |
let tempDiv = document.createElement('div'); | |
let parser= new DOMParser(); | |
return parser.parseFromString(html,"text/html"); | |
} | |
}()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment