window下使用curl库保存网页源码并显示

1 下载curl库:http://curl.haxx.se/download.html


2 下载后解压,进入curl-7.38.0\projects\Windows\VC6目录,使用vs 2010打开项目,选择DLL Release编译

3 新建curl测试项目,创建文件夹include和lib

3 进入目录curl-7.38.0\build\Win32\VC6\DLL Release将libcurl.dll和libcurl.lib分别拷贝到curl项目的include和lib目录下

4 curl测试项目属性—- C/C++ --- 预处理器– 预处理器定义  添加 CURL_STATICLIB

curl测试项目属性—- C/C++--- 常规–附加包含目录  添加include

curl测试项目属性—- 连接器 --- 常规 – 附加库目录 添加lib

7 将curl-7.38.0\include\下的curl目录拷贝到curl测试项目的include目录下

测试程序编写

// pachong.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>  
#include <iostream>  
#include <Windows.h>    
#include "curl/curl.h"    

#pragma comment(lib, "libcurl.lib")     
#pragma comment(lib, "wldap32.lib")     
#pragma comment(lib, "ws2_32.lib")     
#pragma comment(lib, "winmm.lib")     

using namespace std;  

size_t write_data(char *buffer,size_t size, size_t nitems,void *outstream)  
{  
	int written = fwrite(buffer, size, nitems, (FILE*)outstream);  
	return written;  
}  

void  anaylize_data()
{

}

int _tmain(int argc, _TCHAR* argv[])
{
	// 将note.xml写入myxml.xml文件里  
    CURL *pCurl;    
    FILE* pFile = fopen( "myxml.xml", "wb" );  
    pCurl = curl_easy_init();    
    curl_easy_setopt(pCurl, CURLOPT_WRITEDATA, (void*)pFile);  
    curl_easy_setopt(pCurl, CURLOPT_WRITEFUNCTION, write_data);  
    curl_easy_setopt(pCurl, CURLOPT_URL, "http://www.pc28yc.com/pre.php/");  
    curl_easy_perform(pCurl);  
    fclose(pFile);  
    curl_easy_cleanup( pCurl );  
      
    //将note.xml显示在终端上  
    CURL *curl;    
    CURLcode res;    
    curl = curl_easy_init();    
    if(curl)  
    {  
        curl_easy_setopt(curl, CURLOPT_URL, "http://www.pc28yc.com/pre.php/");    
   
        res = curl_easy_perform(curl);    
        curl_easy_cleanup(curl);    
        curl_global_init(CURL_GLOBAL_ALL);    
    }  
    system("pause");  

	//网页已经被down下来了。
	//开始分析里边的数据
	anaylize_data();

	return 0;
}


9 运行结果



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

刘仕豪

IT发展快就是因为有开源精神

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值