-2
有人很高兴给我写一个脚本,允许从跨域网站检索数据。 PHP的是这样的:跨域GET
<?php
if(isset($_GET['site'])){
$f = fopen($_GET['site'], 'r');
$html = '';
while(strpos($html, 'position1_article_1') === FALSE)
$html .= fread($f, 24000);
fclose($f);
echo $html;
}
?>
这是保存为proxy.php jQuery的部分看起来像这样:
$(function(){
var site = 'http://www.nu.nl';
$.get('proxy.php', { site:site }, function(data){
var href = $(data).find('.hdtitle').first().children(':first-child').prop('href');
var url = href.split('/');
href = href.replace(url[2], 'nu.nl');
// Put the 'href' inside your div as a link
$('#myDiv').html('<a href="' + href + '" target="_blank">' + href + '</a>');
}, 'html');
});
的问题是,我无法弄清楚如何让所有的'一个'在身体或某些部分像h2,h3等。有人可以把它分解给我吗?例如;为了获得页面中的所有href,我需要改变什么?
我不太确定你想要做什么,你可以稍微说一下吗? – narruc
http://stackoverflow.com/questions/3627489/php-parse-html-code – ethrbunny
@ShaneCurran我想用脚本做几件事,但我不知道它是如何工作的(我不知道PHP)所以如果有人可以向我解释如何获得身体的所有信息,那么这可以让我更近一步了解它的工作原理。 – Youss