Last active
August 29, 2015 14:08
-
-
Save thinsoldier/d68320ab136850f4a9b5 to your computer and use it in GitHub Desktop.
extracting data from html to json
This file contains hidden or 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
| toplevel = $('#subnav > ul > li > a'); | |
| var all = []; | |
| toplevel.each(function(i,x){ | |
| //console.log(i, x); | |
| var data = {}; | |
| data.id = i + 500; | |
| data.slug = x.href.split('#').pop(); | |
| data.headline = $(x).text(); | |
| //console.log(data) | |
| all.push(data) | |
| } ); | |
| //----------------------------- | |
| sublevel = $('#subnav > ul > li > ul > li > a'); | |
| var all = []; | |
| sublevel.each(function(i,x){ | |
| //console.log(i, x); | |
| var data = {}; | |
| data.id = i + 625; | |
| data.parent_id = 502; | |
| data.slug = x.href.split('#').pop(); | |
| data.headline = $(x).text(); | |
| //console.log(data) | |
| all.push(data) | |
| } ); | |
| JSON.stringify(all); | |
| //----------------------------- | |
| all = []; | |
| var records = $('.fancylistA li').each( extractRecord ); | |
| function extractRecord(index, node) | |
| { | |
| var $node = $(node); | |
| var $anchor = $node.find('a'); | |
| data = {}; | |
| data.id = 10 + index; | |
| data.category = ',888:,'; | |
| data.headline = $node.text(); | |
| if( $anchor.length > 0 ) | |
| { | |
| data.file = $anchor[0].href; | |
| } | |
| all.push(data) | |
| } | |
| $($0).text( JSON.stringify(all) ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment