Created
September 4, 2017 17:12
-
-
Save musou1500/beac16f2ca61c35956301b0ed33566d0 to your computer and use it in GitHub Desktop.
今日のうんちは何かな? https://shindanmaker.com/518611
This file contains 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
const crypto = require('crypto'); | |
const cheerio = require('cheerio'); | |
const fetch = require('node-fetch'); | |
const FormData = require('form-data'); | |
function fetchUntilMatch(postInterval = 500) { | |
const input = crypto.randomBytes(8).toString('hex'); | |
fetchResult(input) | |
.then(result => { | |
console.log(`${input} => ${result}`); | |
if (!result.startsWith('うんち')) { | |
setTimeout(() => fetchUntilMatch(postInterval), postInterval); | |
} | |
}); | |
} | |
function fetchResult(input) { | |
const fd = new FormData(); | |
fd.append('u', input) | |
return fetch('https://shindanmaker.com/518611', { | |
method: 'POST', | |
body: fd, | |
headers: fd.getHeaders() | |
}).then(res => res.text()) | |
.then(html => cheerio.load(html)) | |
.then($ => $('.result2').text().trim()); | |
} | |
fetchUntilMatch(500); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment