0

I don't know if this is possible or allowed, but basically I want to go to http://www.nfl.com/scores and get the scores for a particular week. It seems like each game has a certain class and I could the scores and team easily if I can access their html. I think I need to use AJAX or JSON or some combination. Thanks!

UPDATE:

proxy.php

<html>
    <head>
    </head>

    <body>
        <?php
            $url = "http://www.nfl.com/scores/2012/PRE1http://www.nfl.com/scores/2012/PRE1";
            $htm = file_get_contents($url);
            echo $htm;
        ?>
    </body>
</html>

nflScores.php

<html>
    <head>
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    </head>

    <body>
        <p></p>
        <script type="text/javascript">
            $.get("proxy.php", function(response) { 
    alert(response) });
        </script>
    </body>
</html>

It seems that my alert box is filled with tons of html. Can I use some sort of .getElementByID() method to find certain elements?

Thanks

MikeB
  • 2,402
  • 1
  • 15
  • 24
  • possible duplicate of [Can Javascript read the source of any web page?](http://stackoverflow.com/questions/680562/can-javascript-read-the-source-of-any-web-page) and [Javascript or JQuery get html content from external site](http://stackoverflow.com/questions/11788758/javascript-or-jquery-get-html-content-from-external-site) and potentially others. – Felix Kling Aug 26 '12 at 17:21

3 Answers3

3

This is not possible due to XHR's same-origin policy.

Check if NFL has an API you can use to get the scores. Look at this question. Doesn't look like they have an API released, but you may be able to gather the information anyway.

Community
  • 1
  • 1
Some Guy
  • 15,854
  • 10
  • 58
  • 67
2

Write your server-side (PHP?) script, download nhl.com site, parse html, send to javascript using json or print it directly on your website.

However, i think nfl.com won't be happy about it.

Peter
  • 16,453
  • 8
  • 51
  • 77
1

Either way, the laws around "screen scraping" are pretty grey.

Nate Higgins
  • 2,104
  • 16
  • 21