求一段php抓取題目和超連結的代碼

來源:互聯網
上載者:User
求一段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

    這個函數可以把所有連結和標題都掃出來
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.