linux下C语言如何获取网页源代码

来源:互联网 发布:擎洲广达软件电话 编辑:程序博客网 时间:2024/05/17 02:12

http://bbs.csdn.net/topics/390242602


1.使用ghttp之类的library,发送http请求获取。
2.调用外部程序,比如curl获取。例子,调用curl获取

C/C++ code?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <stdio.h>
#include <stdlib.h>
 
int main(void)
{
    FILE *fp;
    char buf[BUFSIZ];
    if (NULL != (fp = popen("curl http://www.baidu.com""r")))
        fread(buf, BUFSIZ, 1, fp);
    else {
        fprintf(stderr, "popen error...\n");
        exit(1);
    }
    printf("%s\n", buf);
    pclose(fp);
    return 0;
}

-------------------------------------------------------------------

做实验用脚本最快, 你要用C就用libcurl。

-------------------------------------------------------------------

对CURL的一些研究

http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=586014

-------------------------------------------------------------------

c语言 curl

http://blog.csdn.net/zhu244912654/article/details/7454243