Last active
August 29, 2015 14:25
-
-
Save yutin1987/44111921477cf545a446 to your computer and use it in GitHub Desktop.
PTT parse
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
var jsdom = require('jsdom'); | |
var promise = require('bluebird'); | |
var request = require("request"); | |
function getURL(url) { | |
return new Promise(function (resolve, reject) { | |
var target = url; | |
var jar = request.jar(); | |
var cookie = request.cookie("over18=1"); | |
cookie.domain = "www.ptt.cc"; | |
cookie.path = "/"; | |
jar.setCookie(cookie, url, function(error, cookie) { | |
// console.log(error); | |
// console.log(cookie); | |
}); | |
request({ | |
uri: target, | |
method: "GET", | |
jar: jar | |
}, function(error, response, body) { | |
// console.log(response.statusCode); | |
// console.log(body); | |
jsdom.env( | |
body, | |
['http://code.jquery.com/jquery.js'], | |
function (errors, window) { | |
var $ = window.$; | |
var imgs = window.$("img"); | |
console.log(window.$(imgs[0]).attr('src')); | |
resolve(); | |
} | |
); | |
}); | |
var body = ''; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment