2012-08-26 129 views
1

我不知道这是可能的还是允许的,但基本上我想去http://www.nfl.com/scores并获得特定星期的分数。似乎每个游戏都有一定的课程,如果我可以访问他们的html,我就可以轻松获得分数和团队。我想我需要使用AJAX或JSON或某种组合。谢谢!Javascript从外部网站获取html

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> 

看来,我的警告框充满吨的HTML。我可以使用某种.getElementByID()方法来查找某些元素吗?

感谢

+0

可能重复[可以使用Javascript读取任何网页的源代码?](http://stackoverflow.com/questions/680562/can-javascript-read-the-source-of-any-web-page)和[Javascript或JQuery从外部网站获取html内容](可能是其他网站)(http://stackoverflow.com/questions/11788758/javascript-or-jquery-get-html-content-from-external-site)。 –

回答

2

编写您的服务器端(PHP?)脚本,下载nhl.com网站,解析html,使用json发送给javascript或直接在您的网站上打印。

但是,我认为nfl.com不会为此感到高兴。

+0

这似乎是可行的。你能详细说明还是举个例子? – MikeB

+0

[This is good start](http://stackoverflow.com/questions/3409264/how-to-parse-actual-html-from-page-using-curl) – Peter

3

这是不可能的,因为XHR的same-origin policy.

检查NFL有您可以用它来获得分数的API。看看this question。看起来他们看起来并没有发布API,但是无论如何您都可以收集信息。

1

无论哪种方式,围绕“屏幕抓取”的法律都非常灰暗。