我想提取网页中的超链接,不过不是所有的超链接,而是部分超链接,这些超链接和我要查找的关键字相对应,如何处理啊? 各位大虾们,需要你们的帮助啊,急!!!

解决方案 »

  1.   

    取得所有超链接的regex如下
    (h|H)(r|R)(e|E)(f|F)  *=  *('|")?(\w|\\|\/|\.)+('|"|  *|>)?  
    然后每条都判断下是否包含你所说的关键字,用
    if(string1.Container(keyword));
      

  2.   

    楼主所给需求不明确,只能提示你用正则,根据所给关键字,定位对应的超键接,并提取出来
    例如下面的代码中,可以提取出4个以“工程师”为查找关键字的超键接,而所使用的正则也要视你的<a.......>的复杂程度,即是否会出现<a.....<..>...>等特殊情况而定<li><a href='http://job.csdn.net/Jobs/ViewJob/8c864f99941749ad85e925e462dd9e52.aspx' target='_blank' title='税务应用开发工程师'>税务应用开发工程师</a></li><li><a href='http://job.csdn.net/Jobs/ViewJob/7e5ce87944894dffbe216d57f224b5e0.aspx' target='_blank' title='移动应用开发工程师'>移动应用开发工程师</a></li><li><a href='http://job.csdn.net/Jobs/ViewJob/029d7df971cd42d1801fe128bf2dbb80.aspx' target='_blank' title='.net开发工程师(急聘)'>.net开发工程师(急聘)</a></li><li><a href='http://job.csdn.net/Jobs/ViewJob/9f4378a117814bb79b896ac6c834f04e.aspx' target='_blank' title='系统设计师、架构师'>系统设计师、架构师</a></li><li><a href='http://job.csdn.net/Jobs/ViewJob/420468ea874c4bb3be0ad29475500790.aspx' target='_blank' title='ERP最佳实践分析师'>ERP最佳实践分析师</a></li><li><a href='http://job.csdn.net/Jobs/ViewJob/40f83df80b1b491dabc7613ce0e738cf.aspx' target='_blank' title='开发工程师'>开发工程师</a></li>
      

  3.   

    一般来说,这种需求都是通过正则表达式,把需要的内容提取出来,然后再做后续处理,如写入XML或是数据库正则需要根据具体的网页结构来写,没有通用的,楼主问题问得很笼统,很难给你一个具体的答案
      

  4.   

    C#原代源,如哪位高手有更好的做法请发到我邮箱,我的邮箱[[email protected]][email protected][/email] 
        private string AddKeyWord(string strInfo,string strKeyWord,string strKeyWordUrl) 
        { 
            string strInfos = ""; 
            int count; 
            string strUrl = " <a href=\"" + strKeyWordUrl + "\">" + strKeyWord + " </a>"; 
            while (true) 
            { 
                count = strInfo.IndexOf(" <"); 
                if (count != -1) 
                { 
                    strInfos += strInfo.Substring(0, count).Replace(strKeyWord, strUrl); 
                    strInfo = strInfo.Substring(count); 
                    count = strInfo.IndexOf(">"); 
                    if (count != -1) 
                    { 
                        if (strInfo.Substring(0, 2).ToLower() == " <a") 
                        { 
                            count = strInfo.ToLower().IndexOf(" </a>") + 4; 
                            strInfos += strInfo.Substring(0, count); 
                            strInfo = strInfo.Substring(count);                     } 
                        else 
                        { 
                            count++; 
                            strInfos += strInfo.Substring(0, count); 
                            strInfo = strInfo.Substring(count); 
                        } 
                    } 
                    else 
                    { 
                        strInfos += strInfo; 
                        return strInfos; 
                    } 
                } 
                else 
                { 
                    strInfos += strInfo.Replace(strKeyWord, strUrl); 
                    return strInfos; 
                } 
            } 
        }