2013-04-09 57 views
0

我写的代码从dailyhoroscopes.com网站以八字:解析信息从占星网站

<?php 
include('../simple_html_dom.php'); 

// get DOM from URL or file 
$html = file_get_html('http://www.dailyhoroscope.com/?date=yesterday'); 

$needle = 'var ar_interps = '; 
$needle_end = 'var ar_interps_love = '; 

foreach($html->find('script') as $e)  
    if (strpos($e->innertext, $needle) !== false) { 
     $json = substr($e->innertext, strpos($e->innertext, $needle));   
     $json = substr($json, 0, strpos($json, $needle_end)); 
     $json = str_replace($needle, '', $json); 
     $json = str_replace('; ', '', $json); 
     echo '<pre>'; 
     var_dump(json_decode($json, true)); 
     echo '</pre>'; 
     } 
?> 

什么是仅与HTML和JavaScript相同的最佳方式?

+0

你的意思是什么? – bestprogrammerintheworld 2013-04-09 18:58:57

+0

他意味着抓取ajax然后输出它 – bwoebi 2013-04-09 19:01:04

回答

0

你不能。跨网域访问政策不允许网页访问从其他来源加载的内容。在这种情况下,除非您的页面也位于该域中,否则这将不允许您从dailyhoroscope.com加载数据。

此外,未经他们许可重复使用他们的内容可能会构成版权侵犯,即使它不是非法的,它也可能是一种鸡巴移动,因为它最终会在其服务器上产生负载。不要这样做。