有人很高兴给我写了一个允许从跨域站点检索数据的脚本。PHP 看起来像这样:
<?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 等)中获得所有“a”。有人可以把它分解给我吗?例如; 为了获得页面中的所有href,我必须进行哪些更改?