当前位置:编程学习 > C/C++ >>

获取网页某一类的链接

print?根据某一类的url链接有相同的开头,以及相同的位置结束来截取字符串,从而取得其href 

根据某一类的url链接有相同的开头,以及相同的位置结束来截取字符串,从而取得其href
[cpp] void CzcfxDlg::OnBnClickedBtngeturls() 

    // TODO: 在此添加控件通知处理程序代码  
    g_Log.print(LogLevel_Info,"[info] get url start.\n"); 
 
    CFile f; 
    //let's open file and read it into CString (u can use any buffer to read though  
    if (f.Open("klsf.txt", CFile::modeRead|CFile::shareDenyNone)) { 
        //m_wndLinksList.ResetContent();  
        CString csWholeFile; 
        f.Read(csWholeFile.GetBuffer(f.GetLength()), f.GetLength()); 
        csWholeFile.ReleaseBuffer(f.GetLength()); 
        f.Close(); 
 
        int first=0; 
        CString strStart="href=\"/soccer/match"; 
        int end=0; 
        CString strEnd ="target=\"_blank\""; 
 
         
        while(csWholeFile.Find(strStart,first)>end) 
        { 
            CString strUrl=GetVlue(first,first,csWholeFile,strStart,strEnd); 
             
                     

void CzcfxDlg::OnBnClickedBtngeturls()
{
 // TODO: 在此添加控件通知处理程序代码
 g_Log.print(LogLevel_Info,"[info] get url start.\n");

 CFile f;
 //let's open file and read it into CString (u can use any buffer to read though
 if (f.Open("klsf.txt", CFile::modeRead|CFile::shareDenyNone)) {
  //m_wndLinksList.ResetContent();
  CString csWholeFile;
  f.Read(csWholeFile.GetBuffer(f.GetLength()), f.GetLength());
  csWholeFile.ReleaseBuffer(f.GetLength());
  f.Close();

  int first=0;
  CString strStart="href=\"/soccer/match";
  int end=0;
  CString strEnd ="target=\"_blank\"";

  
  while(csWholeFile.Find(strStart,first)>end)
  {
   CString strUrl=GetVlue(first,first,csWholeFile,strStart,strEnd);
   
     [cpp] view plaincopyprint?                  } 
    } 
 

                  }
 }

}[cpp]

 [cpp]  <PRE class=cpp name="code">CString CzcfxDlg::GetVlue(int &end,int last,CString str,CString startStr,CString endStr) 

 
    int start =str.Find(startStr,last); 
    end=str.Find(endStr,start); 
    g_Log.print(LogLevel_Info,"[info] 位置 start=%d,end=%d,last=%d.\n",start,end,last); 
    int iLen1=start+startStr.GetLength(); 
    int iLen2=end-start-startStr.GetLength(); 
    CString result=str.Mid(iLen1,iLen2); 
    g_Log.print(LogLevel_Info,"[info] 名字为 %s.\n",result); 
    return result; 
 

</PRE><BR> 
<PRE></PRE> 
<PRE></PRE> 

补充:软件开发 , C++ ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,