解析信息从占星网站
问题描述:
我写的代码从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相同的最佳方式?
答
没有办法:这个服务器不支持CORS。有关跨源共享的信息,请参阅wikipedia文章。 http://en.wikipedia.org/wiki/Cross-origin_resource_sharing
答
你不能。跨网域访问政策不允许网页访问从其他来源加载的内容。在这种情况下,除非您的页面也位于该域中,否则这将不允许您从dailyhoroscope.com
加载数据。
此外,未经他们许可重复使用他们的内容可能会构成版权侵犯,即使它不是非法的,它也可能是一种鸡巴移动,因为它最终会在其服务器上产生负载。不要这样做。
你的意思是什么? – bestprogrammerintheworld 2013-04-09 18:58:57
他意味着抓取ajax然后输出它 – bwoebi 2013-04-09 19:01:04