Skip to content

Instantly share code, notes, and snippets.

@hxgdzyuyi
Created July 26, 2014 16:24
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 hxgdzyuyi/ccbbd328dc0b2ba92d90 to your computer and use it in GitHub Desktop.
Save hxgdzyuyi/ccbbd328dc0b2ba92d90 to your computer and use it in GitHub Desktop.
创建 codepen.io
var request = require('request')
, cheerio = require('cheerio')
request = request.defaults({jar: true})
var post_data = {id: "",title: "asdf",description: "",slug_hash: "",html: "sasdfs",css: "",js: "", arent: 0,"private": !1,auto_run: !0,html_pre_processor: "none",html_classes: "",head: "",css_pre_processor: "none",css_pre_processor_lib: "",css_prefix: "neither",css_starter: "neither",css_external: "",js_pre_processor: "none",js_library: "",js_modernizr: !1,js_external: "",tags: [],last_updated: "",errorCode: "",savingPenToDB: !1,saveAttempts: 0,MAX_SAVE_ATTEMPTS: 6,SAVE_ATTEMPT_TIMEOUT: 1e4,fork: !1,lastSavedPen: {},redirectingToSavedURL: !1}
request('http://codepen.io', function(error, response, body) {
var $ = cheerio.load(body)
var csrfKey = $('meta[name="csrf-token"]').attr('content')
console.log(csrfKey)
request({
uri: 'http://codepen.io/pen/save'
, method: "POST"
, headers: {
'X-CSRF-Token': csrfKey
}
, form: {
pen: JSON.stringify(post_data)
}
}
, function(error, response, body) {
console.log(body)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment