64,647
社区成员
发帖
与我相关
我的任务
分享
#include "stdafx.h"
#include<iostream> //for std::cout
using namespace std; //for std::cout
#include <afxwin.h> //AfxGetApp()
#include <afxinet.h> //CInternetSession,CHttpFile
CWinApp theApp;
int main(int argc, char* argv[])
{
AfxWinInit(GetModuleHandle(NULL),NULL,GetCommandLine(),0);
HWND hWnd=AfxGetApp()->m_pMainWnd->GetSafeHwnd();
CString csURL,csURL1="http://www.baidu.com/_",csURL3=".html",csLine,csText;
CInternetSession mySession;
CHttpFile* pHttpFile;
for(int i=1;i<=344;i++)
{
csText="";
csURL.Format("%s%d%s",csURL1,i,csURL3);
pHttpFile=(CHttpFile*)mySession.OpenURL(csURL);
while( pHttpFile->ReadString(csLine) )
csText+=csLine+"\r\n";
//cout<<csText<<endl;
if(csText.Find("字")!=-1&&csText.Find("字词")==-1)
cout<<i<<endl;
}
pHttpFile->Close();
mySession.Close();
}
#include<windows.h>
#include<wininet.h>
#include<iostream>
#include <tchar.h>
using namespace std;
#pragma comment(lib,"wininet.lib")
int main()
{
HINTERNET internetopen;
HINTERNET internetopenurl;
char buffer[1024 * 16];
DWORD byteread;
BOOL bReadOK ;
internetopen = InternetOpen(/*_T("DownLoadFile")*/NULL,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0);
if (internetopen==NULL)
{
cout<<"Internet open failed!"<<endl;
return 1;
}
internetopenurl = InternetOpenUrl(internetopen,_T("http://www.baidu.com"),
NULL,0,INTERNET_FLAG_TRANSFER_ASCII|INTERNET_FLAG_PRAGMA_NOCACHE,0); //下载的URL
if (internetopenurl==NULL)
{
cout<<"Internet open url failed! error code = "<<GetLastError()<<endl;
return 1;
}
bReadOK = InternetReadFile(internetopenurl,buffer,sizeof(buffer),&byteread);
if(bReadOK == TRUE)
{
buffer[byteread] = '\0';
cout << buffer << endl;
}
cin.get();
return 0;
}