3
$\begingroup$

I tried importing a webpage using Import:

Import["http://ultrasignup.com/m_results_participant.aspx?fname=Troy&lname=Siemers"];

which should give some info about a runner friend of mine (he gave permission to have his name shown here). Using Import as shown above gives generic HTML information but the table containing the data I want. Using the options "Data" and "FullData" do not give anything useful, either. However, in my web browser I can see the HTML code for the table when I "View Source."

Is there an option for importing a web page in Mathematica that I am overlooking? How do I import the data from the page?

$\endgroup$

1 Answer 1

4
$\begingroup$

The website loads the data via Ajax and then inserts it into the HTML code. It's much easier if you import from the source of the data:

data = Import["http://ultrasignup.com/service/events.svc/history/Troy/Siemers", "JSON"];

You now have all data that is shown on that page in a neat list of rules.

$\endgroup$
7
  • $\begingroup$ That works great - thanks! It also raises a couple of questions. First, how did you know to go to the URL you used? Secondly, (and I know next to nothing of AJAX) if the data is inserted via AJAX into the HTML, can Mathematica not find itself? $\endgroup$
    – GregH
    Mar 24, 2014 at 13:10
  • $\begingroup$ Search source for JSON $\endgroup$
    – martin
    Mar 24, 2014 at 13:13
  • 1
    $\begingroup$ @GregH Every browser has a "developer tool" and in this case I used Google Chrome, so I just opened up the DevTools window and opened the network tab. By reloading the page I got a list of all files that the website requested. It was a matter of going through this list until I found it. If the data comes from Ajax MMA cannot retrieve it by downloading the website source, because Ajax == Javascript only executes in the browser. The Javascript was never executed, so it never inserted the data. $\endgroup$
    – C. E.
    Mar 24, 2014 at 13:25
  • $\begingroup$ "JSON" is just the data format that's being used. It's very common, and it is important to be able to recognize it since often, as in this case, "JSON" doesn't appear anywhere. Not in the source code or anywhere else. $\endgroup$
    – C. E.
    Mar 24, 2014 at 13:26
  • 1
    $\begingroup$ @Pickett Makes sense - thanks! I didn't know about the Developer Tool but it now adds to my problem solving methodology for other situations. $\endgroup$
    – GregH
    Mar 24, 2014 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.