Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
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? –  GregH Mar 24 at 13:10
    
Search source for JSON –  martin Mar 24 at 13:13
1  
@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. –  Pickett Mar 24 at 13:25
    
"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. –  Pickett Mar 24 at 13:26
1  
@Pickett Makes sense - thanks! I didn't know about the Developer Tool but it now adds to my problem solving methodology for other situations. –  GregH Mar 24 at 15:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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