0

This question has to do mostly on how do I find the way to fetch them.

Let's say I have a website with olympic games displaying medals per country per game.

I have a website link http://www.olympic.org/content/results-and-medalists/searchresultpercountry/?athletename=&country=ger&sport2=&games2=&event2=&mengender=true&womengender=true&mixedgender=true&goldmedal=true&silvermedal=true&bronzemedal=true&worldrecord=true&olympicrecord=false&teamclassification=true&individualclassification=true&winter=true&summer=true

This displays the Germany's medals in every event. I want to retrieve the data as an array or something and display them in a table. The first thing I should do is open firebug and search for a json link to parse the data. The only time I have retrieved data from a website was by using twitter's or facebook's json data to show the followers and likes.

How do I find the way to retrieve them ? In the link I posted, how can I fetch data ?

Radolino
  • 1,834
  • 4
  • 26
  • 48
  • 1
    Unless the originating website provides a data API of some sort you cannot retrieve the information as data. – Jay Blanchard Feb 19 '13 at 13:07
  • You can use the `load` method to load via ajax this table (you must kwno the table id) and process it once you got it. – anmarti Feb 19 '13 at 13:08
  • I have read many people that use a DOM parser. Is there something like that in JQuery or another JS library ? – Radolino Feb 19 '13 at 13:08

2 Answers2

0

Try $.get You can pass the callback function to use the data comes from the url specified and print it as you need.

$.get('http://www.yoursite.com/index.html', function(data) {
  $('content').html(data);
  alert('Load was performed.');
});

Accordingly if the returned data is in jSon format then you can easily access all its elements as well with ease.

Cheers

K D
  • 5,889
  • 1
  • 23
  • 35
  • can you send a very very simple jsfiddle to see how it works ? – Radolino Feb 19 '13 at 13:23
  • take a look at it.. We can use it via jQuery.load too in case of simple html. http://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_ajax_load – K D Feb 19 '13 at 13:33
  • but this works for internal content. I want to be able to parse data using websites' links. How do I read another website's data to retrieve the DOM elements that I want? For example I want to retrieve what displays from the link I posted. – Radolino Feb 19 '13 at 13:41
  • It can't with pure jQuery or JavaScript because you can't fetch content from domains different from the one the script is running from. However as a workaround you can get this done with the help of jQuery using IFrame. Set the IFrame URL and get its content after loading using jQuery. Cheers – K D Feb 19 '13 at 13:47
  • But how did I fetch content from twitter and facebook ? Is this because they have public APIs ? This means I must find a public API of the olympic games in order to access their data from my website ? – Radolino Feb 19 '13 at 13:59
0

If the site does not provide public API you cannot get their content with pure Ajax. But nevertheless you can get the content by web scraping. F.ex., you can get the page content by PHP script, extract the data you need from HTML, format it to JSON or XML and pass it to your Ajax request.

Take a look at an example here and at this question.

Community
  • 1
  • 1
bancer
  • 7,475
  • 7
  • 39
  • 58
  • I have been asked to fetch some data from a website that does not have any public API with any Javascript library. This is to be done as an exercise and I am seeking ways to develop this. If you can't fetch a website's data from the span ids using js then there is no meaning. It's easy to complete this in PHP but the exercise says only HTML5 & any JS library. – Radolino Feb 19 '13 at 19:51
  • http://stackoverflow.com/questions/5211486/scrape-web-pages-in-real-time-with-node-js – bancer Feb 19 '13 at 23:27