获取网页某一类的链接

2014-11-23 23:55:30 · 作者: · 浏览: 4

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]

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;

}