Sunday, 15 September 2013

Does JS code contain an opening to hidden data? (Yes or no, probably)

Does JS code contain an opening to hidden data? (Yes or no, probably)

I would like to know, as one with very little JS experience, wether or not
this code contains a way for me to access more information. Here is an
example of a page which I am trying to scrape.
http://www.hannaford.com/product/8-piece-Mini-Sweet-Pepper-Carton/841589.uts?
I want the nutritional information. I could go to every food page on the
website and get every piece of data from the nutrition tables, but that
would take ages. I already have all of the other information from the
foods that I want, having done that by scraping from pages where there
were longer lists. (I could scrape in bulk)
So I am asking if anyone sees anything here that might grant me access to
wherever it is they are calling their nutrition data from, so I could load
up that one page and scrape from there, en masse.
<script type="text/javascript">
$(function() {
$('#primaryNutrition dd').each(function(){
var that = $(this);
var txt = $.trim(that.html());
if (txt.length > 0){
var values = txt.split(' ');
if ( values.length > 1 ){
if ( values[1].indexOf("%") === -1){
values[0] += values.pop();
}
}
if ( values.length > 1 ){
that.html(values[0]);
var newDD = document.createElement('dd');
newDD.innerHTML = values[1];
this.parentNode.appendChild(newDD);
} else {
that.addClass('one');
}
} else {
that.parent().hide();
}
});
});
</script>
My read on the situation is that the "#primary..." tells it to write to
that particular div id somehow. I do find interesting the "
$.trim(that.html()); " bit. I don't know enough to tell what is defined
and what is just part of javascript.
I picked that little snippet because it is what I thought was likely to
yield a positive result for me, but if someone sees something else on the
page, then that would be good too.

No comments:

Post a Comment