Skip to content

Instantly share code, notes, and snippets.

@PabloWestphalen
Created January 19, 2019 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PabloWestphalen/c7e04d7654493ddf3c5c86a96395a0c1 to your computer and use it in GitHub Desktop.
Save PabloWestphalen/c7e04d7654493ddf3c5c86a96395a0c1 to your computer and use it in GitHub Desktop.
(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