Skip to content

Instantly share code, notes, and snippets.

@yutin1987
Last active August 29, 2015 14:25
Show Gist options
  • Save yutin1987/44111921477cf545a446 to your computer and use it in GitHub Desktop.
Save yutin1987/44111921477cf545a446 to your computer and use it in GitHub Desktop.
PTT parse
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