zoukankan      html  css  js  c++  java
  • 打开一个网页,以html代码保存于txt文件中

    #include <string> 
    #include <iostream> 
    #include <fstream> 
    #include <windows.h> 
    #include <wininet.h> 
    #include <winsock.h> 
    #include <stdio.h> 
    #include <stdarg.h>  
    
    #pragma comment(lib,"wininet.lib") 
    using namespace std;  
    int main()       
    { 
        HINTERNET hOpen, hURL; 
        LPCWSTR NameProgram = L"Webreader";       //      LPCWSTR == Long Pointer to Const Wide String  
        LPCWSTR Website;                     
        char file[101]; 
        unsigned long read;  //Always need to establish the internet connection with this funcion.     
        if ( !(hOpen = InternetOpen(NameProgram, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 )))     
        {
            cerr << "Error in opening internet" << endl;     
            return 0;     
        }                        
        Website = L"http://www.baidu.com"; 
        hURL = InternetOpenUrl( hOpen, Website, NULL, 0, 0, 0 );            //Need to open the URL   
        InternetReadFile(hURL, file, 100, &read);
        
        string filename="top_level_domain.ini";
        ofstream pfile_top_domain(filename.c_str());
        
        if(!pfile_top_domain.is_open())
        {
            cerr << "couldn't read config file.\n";
            return 0;
        }
            file[read] = '\0';     
            pfile_top_domain<<file;   
        while (read == 100)     {    
            InternetReadFile(hURL, file, 100, &read);    
            file[read] = '\0';     
            pfile_top_domain<<file;    
        }  
        cout << endl; 
        InternetCloseHandle(hURL);
        
        return 0; 
    } 
  • 相关阅读:
    bzoj4554: [Tjoi2016&Heoi2016]游戏
    bzoj3166: [Heoi2013]Alo
    luogu3398 仓鼠找sugar
    bzoj3261: 最大异或和
    bzoj3446: [Usaco2014 Feb]Cow Decathlon
    BZOJ1742[Usaco2005 nov]Grazing on the Run 边跑边吃草
    bzoj2750: [HAOI2012]Road
    bzoj4448: [Scoi2015]情报传递
    bzoj2809: [Apio2012]dispatching
    bzoj 1452
  • 原文地址:https://www.cnblogs.com/upendi/p/2631826.html
Copyright © 2011-2022 走看看