• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

求一段php抓取题目和超链接的代码

php 搞代码 3年前 (2022-01-24) 24次浏览 已收录 0个评论

求一段php抓取标题和超链接的代码
比如说http://xcb.nuist.edu.cn/e/wap/list.php?classid=6&style=0&bclassid=1
页面上的新闻”标题”+”时间”+”超链接”

小弟不胜感激,希望直接可以用,网上的我有点用不了,本人没有php基础,还望理解

如果有朋友使用正则表达式来做的话,

  • ].+>(.+)(.+)
  • 这个希望能有点帮助

    php 正则表达式 抓取数据

    ——解决方案——————–

    $s=file_get_contents('http://xcb.nuist.edu.cn/e/wap/list.php?classid=6&style=0&bclassid=1');<br />preg_match_all(<em style="color:transparent">本文来源gao.dai.ma.com搞@代*码#网</em><a>搞代gaodaima码</a>'/<li>]*>(.+)<span>(.+)<\/span><\/a><\/li>/isU',$s,$m);<br />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://&#8221;))
    {
    $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/&#8221;, $arrAhef, $arrLink, $arrTitle, $strLinkAll); //ioooo

    这个函数可以把所有链接和标题都扫出来


    搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
    转载请注明原文链接:求一段php抓取题目和超链接的代码

    喜欢 (0)
    [搞代码]
    分享 (0)
    发表我的评论
    取消评论

    表情 贴图 加粗 删除线 居中 斜体 签到

    Hi,您需要填写昵称和邮箱!

    • 昵称 (必填)
    • 邮箱 (必填)
    • 网址