javascript - Need some help scraping with CasperJS -


this have:

var casper = require('casper').create();  var fs = require('fs'); var foldername = 'card_data'; var filename = 'championdecks.txt'; var save = fs.pathjoin(fs.workingdirectory, foldername, filename);  // init jquery  var casper = require('casper').create({     clientscripts: ['jquery.min.js'] });  // parse url var parseurl = 'http://magic.wizards.com/en/events/coverage/mtgochamp14';  // scrape function getdeckdata() {     var meta = $('.deck-meta h4').text();     var event = $('.deck-meta h5').text().trim();      return [meta, event]; }  casper.start(parseurl, function() {     var data = this.evaluate(getdeckdata);      fs.write(save, data + '\n', 'w'); });  casper.run(); 

i'm trying scrape http://magic.wizards.com/en/events/coverage/mtgochamp14 in format looks similar this:

{     "event": "2014 magic online championship",     "deckname": "(vintage) magnus lantto's pyromancer control",     "deck": [         "1 dack fayden",         "3 snapcaster mage",         "4 young pyromancer",         "3 cabal therapy",         "1 demonic tutor",         "4 gitaxian probe",         "1 ponder",         "3 preordain",         "1 time walk",         "1 treasure cruise",         "1 ancestral recall",         "1 brainstorm",         "3 dig through time",         "4 force of will",         "3 gush",         "3 lightning bolt",         "4 mental misstep",         "1 pyroblast",         "1 black lotus",         "1 mox jet",         "1 mox ruby",         "1 mox sapphire",         "3 flooded strand",         "1 island",         "4 scalding tarn",         "1 strip mine",         "2 underground sea",         "3 volcanic island"     ],     "sideboard": [         "1 pyroblast",         "1 dread of night",         "1 electrickery",         "4 grafdigger's cage",         "4 ingot chewer",         "1 mountain",         "1 null rod",         "2 pulverize"     ],     "event": "2014 magic online championship",     "deckname": "(modern) magnus lantto's elf company",     "deck": [ ... ],     "sideboard": [ ... ]      ...and on... } 

i can't seem figure out how data individually. i'm getting:

(vintage) magnus lantto's pyromancer control(modern) magnus lantto's elf company(standard) magnus lantto's atarka devotion(vintage) jasper de jong's mentor control(modern) jasper de jong's melira , company(standard) jasper de jong's green-white devotion(vintage) aleksa telarov's delver(modern) aleksa telarov's burn(standard) aleksa telarov's jund megamorph(vintage) antonio del moral león's omni-oath(modern) antonio del moral león's splinter twin(standard) antonio del moral león's abzan midrange,2014 magic online championship                                               2014 magic online championship                                               2014 magic online championship                                               2014 magic online championship                                               2014 magic online championship                                               2014 magic online championship                                               2014 magic online championship                                               2014 magic online championship                                               2014 magic online championship                                               2014 magic online championship                                               2014 magic online championship                                               2014 magic online championship 

can provide little wisdom send me in right direction?

assuming there event each deck name:

var meta = $('.deck-meta h4'); var event = $('.deck-meta h5'); var output = [];  for(var = 0; < meta.length; i++) {     output.push({         deckname: $(meta[i]).text(),         event: $(event[i]).text().trim()     });     }  return output; 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -