老师要求:利用现有的一些搜索引擎如google,根据指定关键字进行查询,然后自编程序将这些查出的相关页面全部下载下来,不知这一目的如何实现?delphi能不能实现?有没有现成的程序或者工具?对于提供有益帮助者可适当加分
解决方案 »
- adoquery添加多条记录后,再更新数据库,如何实现
- delphi编译错误求助
- 三层结构中,当客户端数据更新回服务器后,客户端数据集CDSDetail.Refresh时出错?
- DataModule单元与一般的窗体单元有何区别?请不吝指教,谢谢!
- 如何让Edit只能输入数字和字母?
- 图形工具:怎样在bmp的放大状态下画线,写字等(画的线条也有放大效果),就象window的画图工具一样。
- 在SQLServer中的问题
- 怎样判断本机安装的是win98 还是 win2000
- 在主菜单的一个选项上设了checked为true.但是运行后前面的勾根本去不掉,这是怎么回事,还有什么地方要设置吗?
- 怎样判断当前桌面未被遮挡?
- 使用TIdTcpServer和TIdTcpClient的问题.请各位帮忙.
- 如何得到脚本变量
int COAMinderDlg::GetTaskAmount()
{
iAmount=0;
iMsgAmount=0;
iFileAmount=0;
CInternetSession m_Session("DigitalTitan");
CHttpConnection* pServer=NULL;
CHttpFile* pFile=NULL;
CHttpFile* pTaskFile=NULL;
CString strServerName=strServerIP;
INTERNET_PORT nPort=(INTERNET_PORT)atoi(strServerPort);
CString strURL=strLoginAddress;
try
{
pServer=m_Session.GetHttpConnection(strServerName,nPort);
pFile=pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST,strURL,NULL,1,NULL,NULL,INTERNET_FLAG_EXISTING_CONNECT);
CString strHeaders=_T("Content-Type: application/x-www-form-urlencoded");
CString strFormData;
strFormData.Format("UserName=%s&Password=%s&action=submit",strLoginUserName,strLoginPassword);
//AfxMessageBox(strFormData,MB_ICONINFORMATION);
if(pFile->SendRequest(strHeaders,(LPVOID)(LPCTSTR)strFormData,strFormData.GetLength())==0)
{
//AfxMessageBox("网络异常...",MB_ICONINFORMATION);
pFile->Close();
delete pFile;
pServer->Close();
delete pServer;
m_Session.Close();
}
else
{
pFile->ReadString(strInfo);
if(strInfo.Find("Apache Tomcat/4.1.18 - Error report",0)!=-1)
{
AfxMessageBox("服务器产生错误.",MB_ICONINFORMATION);
return 0;
}
pFile->Close();
delete pFile;
pServer->Close();
delete pServer;
pTaskFile=(CHttpFile*)m_Session.OpenURL(strLoginDataAddress);
CString strBuf;
CString strText;
while(pTaskFile->ReadString(strText))
{
strBuf+="\r\n";
strBuf+=strText;
}
pTaskFile->Close();
delete pTaskFile;
m_Session.Close();
//AfxMessageBox(strBuf,MB_ICONINFORMATION);
int iBegin,iEnd;
iBegin=0;iEnd=0;
CString strTemp;
strTemp="";
//信息提取
//关键字一
iBegin=strBuf.Find("更多方案",0);
if(iBegin!=-1)
{
//关键字二
iEnd=strBuf.Find("已办理方案</font>",iBegin);
strTemp=strBuf.Mid(iBegin+9,iEnd-(iBegin+9));
strTemp.MakeLower();
//分隔符
int iResult=strTemp.Find("<tr",0);
if(iResult==-1)
{
//
}
else if(iResult<strTemp.GetLength())
{
while(iResult!=-1)
{
iAmount++;
iResult=strTemp.Find("<tr",iResult+3);
}
//修正结果
iAmount=iAmount-5;
}
}
//另关键字:新申请(3)新归档方案(0)
iBegin=strBuf.Find("新申请(",0);
iEnd=strBuf.Find(")",iBegin);
strTemp=strBuf.Mid(iBegin+9,iEnd-(iBegin+9));
iMsgAmount=atoi(strTemp); iBegin=strBuf.Find("新归档方案(",0);
iEnd=strBuf.Find(")",iBegin);
strTemp=strBuf.Mid(iBegin+13,iEnd-(iBegin+13));
iFileAmount=atoi(strTemp);
}
}
catch(CInternetException* e)
{
char strErrorBuf[255];
e->GetErrorMessage(strErrorBuf,255,NULL);
AfxMessageBox(strErrorBuf,MB_ICONINFORMATION);
pFile=NULL;
delete pFile;
pTaskFile=NULL;
delete pTaskFile;
pServer=NULL;
delete pServer;
m_Session.Close();
return 0;
}
return iAmount;
}
CString CDownInfoDlg::DownURL(CString strURL)
{
CInternetSession m_Session("DigitalTitan");
CHttpFile* pFile=NULL;
CException* e; TCHAR szTempPath[MAX_PATH],szTempFile[MAX_PATH];
DWORD dwResult=::GetTempPath(MAX_PATH,szTempPath);
CString strURLPath;
GetTempFileName(szTempPath,_T("DigitalTitan_"),0,szTempFile);
strURLPath=szTempFile;
TRY
{
pFile=(CHttpFile*)m_Session.OpenURL(strURL);
}
CATCH_ALL(e)
{
pFile=NULL;
AfxMessageBox("URL地址不合法",MB_ICONINFORMATION);
return "";
}
END_CATCH_ALL if(pFile)
{
DWORD dwStatus;
DWORD dwBufLen=sizeof(dwStatus);
BOOL bSuccess=pFile->QueryInfo(HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER,&dwStatus,&dwBufLen);
if(bSuccess&&dwStatus>=200&&dwStatus<300)
{
CStdioFile m_File;
if(m_File.Open(strURLPath,CFile::modeWrite|CFile::modeCreate|CFile::typeBinary))
{
BYTE pBuf[1024];
DWORD dwRead;
do
{
dwRead=pFile->Read(pBuf,1024);
m_File.Write(pBuf,dwRead);
}
while(dwRead>0);
m_File.Close();
}
}
pFile->Close();
delete pFile;
}
else
{
m_Session.Close();
}
return strURLPath;
}
var
i: Integer;
Source: OleVariant;
begin
if WebBrowser1.OleObject.Document.all.tags('A').Length = 0 then Exit;
Memo1.Clear; for i := 0 to WebBrowser1.OleObject.Document.all.tags('A').Length - 1 do
begin
Source := WebBrowser1.OleObject.Document.all.tags('A').Item(i);
Memo1.Lines.Add( Source.innerText + ': ' + Source.href );
end;
end;procedure TForm1.Button1Click(Sender: TObject);
var strURL: String;
begin
Edit1.Text := 'Delphi';
Edit2.Text := '100';
strURL := 'http://www.google.com/search?hl=zh-CN&ie=UTF-8'; //参数hl,ie可省
strURL := strURL + '&q='+Edit1.Text; // 要捜査的関鍵字
strURL := strURL + '&num='+Edit2.Text; // 可限定数量
WebBrowser1.Navigate(strURL); while Webbrowser1.ReadyState <> READYSTATE_COMPLETE do
Application.ProcessMessages; //本頁下載完了 GetHref; //取得相関网頁Addr
end;注:用到「TWebBrowser」控件、利用「google」搜索引擎、在「Edit1.Text」中
輸入关键字後、按「Button1」
本例只取得网頁Addr、若要下载可用「DownloadFile(Source, Dest)」函数。