求一段php抓取標題和超連結的代碼
比如說http://xcb.nuist.edu.cn/e/wap/list.php?classid=6&style=0&bclassid=1
頁面上的新聞"標題"+"時間"+"超連結"
小弟不勝感激,希望直接可以用,網上的我有點用不了,本人沒有php基礎,還望理解
如果有朋友使用Regex來做的話,
].+>(.+)(.+)
這個希望能有點協助
php Regex 抓取資料
------解決方案--------------------
$s=file_get_contents('http://xcb.nuist.edu.cn/e/wap/list.php?classid=6&style=0&bclassid=1');
preg_match_all('/]*>(.+)(.+)<\/span><\/a><\/li>/isU',$s,$m);
print_r($m);
------解決方案--------------------
function func_globalscanlink($strUrl, &$arrAhef, &$arrLink, &$arrTitle, &$strLinkAll)
{
$strText = func_ToUtf8(func_ReadPage($strUrl));
$strText = func_WebFillup($strUrl, $strText);
if(!preg_match_all("/(]*href[ ]*=[ ]*\"([^<>]*?)\"[^<>]*>(.*?)<\/a>)/si", $strText, $arr2A_mat))
return 0;
$strLinkAllTem = "";
for($i = 0; $i < count($arr2A_mat[0]); $i++)
{
$strLinkTem = $arr2A_mat[2][$i];
if(strlen($strLinkTem) < 10)
continue;
if(!strpos(" ".$strLinkAllTem, $strLinkTem) && strpos(" ".$strLinkTem, "http://"))
{
$strTitleTem = $arr2A_mat[3][$i];
$strTitleTem = preg_replace("/<.*?.>/si", "", $strTitleTem);
if(strlen($strTitleTem) > 6)
{
$arrAhef[count($arrAhef)] = $arr2A_mat[1][$i];
$arrLink[count($arrLink)] = $strLinkTem;
$strTitle = $arr2A_mat[3][$i];
if(preg_match("/TITLE=\"(.*?)\"/si", $strTitle, $arrTitle_mat))
$strTitle = $arrTitle_mat[1];
$arrTitle[count($arrTitle)] = $strTitle;
$strLinkAll = $strLinkAll.$strLinkTem."\r\n";
$strLinkAllTem = $strLinkAllTem.$arr2A_mat[2][$i]."\r\n";
}
}
// $strLinkAllTem = $strLinkAllTem.$arr2A_mat[2][$i]."\r\n";
}
return $strText;
}
func_globalscanlink("http://www.baidu.com/", $arrAhef, $arrLink, $arrTitle, $strLinkAll); //ioooo
這個函數可以把所有連結和標題都掃出來