これは小さなプログラムで、私は&をテキストファイルに保存/書き出します。必要に応じて変更することができます( ""を "http://www.google.com/"と変更できます)。wininet.a(ライブラリ)をプロジェクトにリンクしてください。それは:)
#include <windows.h>
#include <wininet.h>
#include <iostream>
#include <conio.h>
#include <fstream.h>
fstream fs_obj;
using namespace std;
int main(int argc, char *argv[])
{
fs_obj.open("temp.txt",ios::out | ios::app);
HINTERNET hInternet = InternetOpenA("InetURL/1.0", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
HINTERNET hConnection = InternetConnectA(hInternet, "www.facebook.com", 80, " "," ", INTERNET_SERVICE_HTTP, 0, 0); //enter url here
HINTERNET hData = HttpOpenRequestA(hConnection, "GET", "/", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
char buf[ 2048 ] ;
HttpSendRequestA(hData, NULL, 0, NULL, 0) ;
string total;
DWORD bytesRead = 0 ;
DWORD totalBytesRead = 0 ;
while(InternetReadFile(hData, buf, 2000, &bytesRead) && bytesRead != 0)
{
buf[ bytesRead ] = 0 ; // insert the null terminator.
total=total+buf;
printf("%d bytes read\n", bytesRead) ;
totalBytesRead += bytesRead ;
}
fs_obj<<total<<"\n--------------------end---------------------\n";
fs_obj.close();
printf("\n\n END -- %d bytes read\n", bytesRead) ;
printf("\n\n END -- %d TOTAL bytes read\n", totalBytesRead) ;
cout<<endl<<total<<endl; //it will save source code to (temp.txt) file
InternetCloseHandle(hData) ;
InternetCloseHandle(hConnection) ;
InternetCloseHandle(hInternet) ;
system("pause");
}
は、あなたがそのWebページを取得するブラウザーで開き、temp.htmlでTEMP.TXT名前を変更するのに役立ちます願っています。
'libcurl'を試してください。 –
@LightnessRacesinOrbitいいえ、それはこの質問をクロールすると落ち込んでくるでしょう:) – sehe
@sehe:True that –