网页抓取和ftp访问是目前很常见的一个应用需要,无论是搜索引擎的爬虫,分析程序,资源获取程序,WebService等等都是需要的,自己开发抓取库当然是最好了,不过开发需要时间和周期,使用现有的Open source程序是个更好的选择,一来别人已经写的很好了,就近考验,二来自己使用起来非常快速,三来自己还能够学习一下别人程序的优点。
闲来无事,在网上浏览,就发现了这些好东西,特别抄来分享分享。主要就是libwww、libcurl、libfetch 这三个库,当然,还有一些其他很多更优秀库,文章后面会有简单的介绍。
以下资料来源:
http://9.douban.com/site/entry/15448100/,
http://zh.wikipedia.org/wiki/Libwww简介:Libwww 是一个高度模组化用户端的网页存取API ,用C语言写成,可在 Unix 和 Windows 上运行。 It can be used for both large and small applications including: browsers/editors, robots and batch tools. There are pluggable modules provided with Libwww which include complete HTTP/1.1 with caching, pipelining, POST, Digest Authentication, deflate, etc. The purpose of libwww is to serve as a testbed for protocol experiments. 蒂姆·伯纳斯-李 在 1992 年十一月创造出了 Libwww,用於展示网际网路的潜能。使用 Libwww 的应用程式,如被广泛使用的命令列文字浏览器 Lynx 及 Mosaic web browser 即是用 Libwww 所写成的。 Libwww 目前为一开放原始码程式,并於日前移至 W3C 管理。基於其为开放原始码的特性,任何人都能为 Libwww 付出一点心力,这也确保了 Libwww 能一直进步,成为更有用的软体。
操作示例:
最近我需要写点页面分析的东西,这些东西某些程度上类似搜索引擎的“爬虫->parser->存储”的过程。
过去我常用的抓取页面的库是
libcurl,这个东西是unix常用命令curl的基础,curl被称做“命令行浏览器”,功能强大,支持的协议也全面。遗憾的是libcurl仅仅是个支持多协议的抓取库,不能做解析。
找来找去,发现了w3c的
Libwww库,这东西功能强大的吓人,不仅有解析,还有robot(也就是爬虫了,或是叫internet walker)功能。在Libwww基础上完成的程序很多,最著名的大概是字符模式的浏览器lynx。我几乎就觉得这就我需要的东西了,立刻dive into。
一整天之后,我终于能用这东西抓下来页面,并且从html页面中分析出来一些信息了,但是想更进一步就变的异常困难。因为这个库功能太复杂了。这东西文档不详细,被人提及的也少。Libwww最近的Release 5.3.2,发布于2000年12月20日。一个有这么多年历史的东西,竟然没多少开发者在讨论,非常不正常。
找来找去,最后在libcurl的FAQ里面看到了和Libwww的
比较,精选的读者来信告诉我,不仅仅是我一个人被Libwww的复杂弄的晕了头脑,我才花了一整天,写信的那个哥们竟然用了一人月,还是在里面打转,直到换了curl才好。虽然这是libcurl推销自己的方法,不过这些失败的前辈的经验让我对自己的智商重新有了信心。看来这东西没多少人讨论是正常的...
好吧,我也投降,libcurl没html解析功能,这没关系,我找别的办法好了...这么复杂的库,再好我也实在没办法忍受下去了,再说我需要的功能其实也真没Libwww那么复杂的。
写程序其实很容易迷失,你会看到一个似乎很完美,什么都能做的东西,一下子就喜欢上它,但是最后往往还是无福消受。往往是那些,不那么成熟,多少有点小毛病的库,组合在一起才是真正的解决方案。
【libcurl】
Libcurl为一个免费开源的,客户端url传输库,支持FTP,FTPS,TFTP,HTTP,HTTPS,GOPHER,TELNET,DICT,FILE和LDAP,跨平台,支持Windows,Unix,Linux等,线程安全,支持Ipv6。并且易于使用。
从http://curl.haxx.se/libcurl/ 下载一个稳定的版本,注意选择OS。
编译libcurl
下载下来的是源码包,需要编译。
解压zip文件,进入curl-7.14.0/lib目录(我下载的是7.14.0)。
编译Debug版本。新建一个批处理bat文件,如buildDebug.bat,内容如下:
call "C:/Program Files/Microsoft Visual Studio/VC98/Bin/vcvars32.bat"
set CFG=debug-dll-ssl-dll-zlib-dll
set OPENSSL_PATH=E:/SSL/openssl-0.9.7e
set ZLIB_PATH=E:/zip/zlib123
nmake -f Makefile.vc6
其输出:libcurld_imp.lib, libcurld.dll
编译Release版本。新建一个批处理文件BuildRelease.bat,内容如下:
call "C:/Program Files/Microsoft Visual Studio/VC98/Bin/vcvars32.bat"
set CFG=release-dll-ssl-dll-zlib-dll
set OPENSSL_PATH=E:/SSL/openssl-0.9.7e
set ZLIB_PATH=E:/zip/zlib123
nmake -f Makefile.vc6
其输出:libcurl_imp.lib, libcurl.dll
如果需要编译其他版本,可查看Makefile.vc6,设定相应的CFG 参数即可。
商业软件使用libcurl时,只需要包含其copywrite声明即可。
Sample
#include<stdio.h>
#include"../curl-7.14.0/include/curl/curl.h"
#pragmacomment(lib,"../curl-7.14.0/lib/libcurl_imp.lib")
intmain(void)
{
curl=curl_easy_init();
if(curl){
CURLcoderes;
res=curl_easy_setopt(curl,CURLOPT_PROXY,"Test-pxy08:8080");
res=curl_easy_setopt(curl,CURLOPT_PROXYTYPE,CURLPROXY_HTTP);
res=curl_easy_setopt(curl,CURLOPT_URL,"http://www.vckbase.com");
res=curl_easy_perform(curl);
if(CURLE_OK==res){
char*ct;
/**//*askforthecontent-type*/
/**//*http://curl.haxx.se/libcurl/c/curl_easy_getinfo.html*/
res=curl_easy_getinfo(curl,CURLINFO_CONTENT_TYPE,&ct);
if((CURLE_OK==res)&&ct)
printf("WereceivedContent-Type:%s",ct);
}
/**//*alwayscleanup*/
curl_easy_cleanup(curl);
}
return0;
}
前几天无双老大在FB版介绍了一下CU的巨猛的法老级灌水大师,小弟于是说要编个程序自动来灌,哈哈昨晚有所突破,找到一个很好的库,先介绍给各位大鱼小虾们,不过可别真的拿它来灌水啊,否则我被这里的班长们砍死以后的冤魂可要来算帐的喔!

这是在FreeBSD里找到的一个库:libfetch,源代码在/usr/src/lib/libfetch里,它对http和ftp协议进行了封装,提供了一些很容易使用的函数,因为昨天刚看到,还没仔细研究,我试了一个用http取网页的函数,示例如下:
#include<stio.h>
#include
#include
#include"fetch.h"
constchar*myurl="http://qjlemon:aaa@192.169.0.1:8080/test.html";
main()
{
FILE*fp;
charbuf[1024];
fp=fetchGetURL(myurl,"";
if(!fp){
printf("error:%s ",fetchLastErrString);
return1;
}
while(!feof(fp)){
memset(buf,0,sizeof(buf));
fgets(buf,sizeof(buf),fp);
if(ferror(fp))
break;
if(buf[0])
printf("%s",buf);
else
break;
}
fclose(fp);
fp=NULL;
}
这里最重要的就是fetchGetURL函数,它按指定的URL来取文件,比如URL
是以http开头的,这个函数就知道按http取文件,如果是ftp://,就会按ftp取文件,还可以指定用户名和口令。
如果文件被取到,它会返回一个FILE指针,可以象操作普通的文件一样把网页的内容取出来。
另外这个库还提供了一些函数,可以对网络操作进行更为精细的控制。
当然最有用的是还是几个PUT函数,想要灌水就得用这个哟!哈哈哈!
Free Software and Open Source projects have a long tradition of forks and duplicate efforts. We enjoy "doing it ourselves", no matter if someone else has done something very similar already.
Free/open libraries that cover parts of libcurl's features:
a highly portable and easy-to-use client-side URL transfer library, supporting FTP, FTPS, HTTP, HTTPS, SCP, SFTP, TELNET, DICT, FILE, TFTP and LDAP. libcurl also supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading, kerberos, HTTP form based upload, proxies, cookies, user+password authentication, file transfer resume, http proxy tunnelling and more!
Having a glance at libghttp (a gnome http library), it looks as if it works rather similar to libcurl (for http). There's no web page for this and the person who's email is mentioned in the README of the latest release I found claims he has passed the leadership of the project to "eazel". Popular choice among GNOME projects.
More complex, and and harder to use than libcurl is. Includes everything from multi-threading to HTML parsing. The most notable transfer-related feature that libcurl does not offer but libwww does, is caching.
C++ library "for transferring files via http, ftp, gopher, proxy server". Based on 'snarf' 2.0.9-code (formerly known as libsnarf). Quote from freshmeat: "As the author of snarf, I have to say this frightens me. Snarf's networking system is far from robust and complete. It's probably full of bugs, and although it works for maybe 85% of all current situations, I wouldn't base a library on it."
An HTTP and WebDAV client library, with a C interface. I've mainly heard and seen people use this with WebDAV as their main interest.
Part of glib (GNOME). Supports: HTTP 1.1, Persistent connections, Asynchronous DNS and transfers, Connection cache, Redirects, Basic, Digest, NTLM authentication, SSL with OpenSSL or Mozilla NSS, Proxy support including SSL, SOCKS support, POST data. Probably not very portable. Lacks: cookie support, NTLM for proxies, GSS, gzip encoding, trailers in chunked responses and more.
Handles URLs, protocols, transports for the Mozilla browser.
Minimal download library targeted to be much smaller than the above mentioned netlib. HTTP and FTP support.
While not a library at all, I've been told that people sometimes extract the network code from it and base their own hacks from there.
Does HTTP and FTP transfers (both ways), supports file: URLs, and an API for URL parsing. The utility fetch that is built on libfetch is an integral part of the FreeBSD operating system.
"a small, robust, flexible library for downloading files via HTTP using the GET method."
"a very small C library to make http queries (GET, HEAD, PUT, DELETE, etc.) easily portable and embeddable"
(Windows) Provides client-side protocol support for communication with HTTP servers. A client computer can use the XMLHTTP object to send an arbitrary HTTP request, receive the response, and have the Microsoft® XML Document Object Model (DOM) parse that response.
QHttp is a class in the Qt library from Troll Tech. Seems to be restricted to plain HTTP. Supports GET, POST and proxy. Asynchronous.
"a set of routines that implement the FTP protocol. They allow applications to create and access remote files through function calls instead of needing to fork and exec an interactive ftp client program."
A C++ library for "easy FTP client functionality. It features resuming of up- and downloads, FXP support, SSL/TLS encryption, and logging functionality."
Has a URLStream class. This C++ class allow you to download a file using HTTP. See demo/urlfetch.cpp in commoncpp2-1.3.19.tar.gz
Java HTTP client library.
A Java HTTP client library written by the Jakarta project.
相关推荐
libcurl 是一个用于处理 URL 的客户端库,能够通过各种不同的协议(如 FTP、HTTP、SCP 等)实现文件在网络上的传输。最初,curl 是作为一个命令行工具设计出来的,随着时间的发展,它逐渐演化成了一个强大的库——...
W3C Libwww,也称为Libwww-Perl,是由W3C开发的一个跨平台的HTTP客户端库。它最初是为了支持W3C的内部项目而创建的,但随着时间的发展,它变得足够成熟,可以被其他开发者用于构建各种需要HTTP功能的应用程序。...
版本5.4.0是对这个库的一次重要更新,带来了更多的功能和优化。本文将详细介绍W3C Libwww库的基本概念、核心功能以及在C++中的应用。 1. **基本概念** W3C Libwww库是基于C++语言的,它提供了HTTP协议的低级别接口...
`libwww`可能是一个库,例如W3C的Libwww-Perl,用于辅助实现FTP功能,提供了网络I/O、HTTP和FTP协议的支持。 学习这个源代码,编程新手可以了解网络编程的基本原理,如何处理套接字,以及如何实现与远程服务器的...
libwww-robotrules-perl libxml-libxml-perl libxml-namespacesupport-perl libxml-parser-perl libxml-sax-base-perl libxml-sax-expat-perl libxml-sax-perl texinfo 升级了 0 个软件包,新安装了 28 个软件包,...
libwww-robotrules-perl libxml-libxml-perl libxml-namespacesupport-perl libxml-parser-perl libxml-sax-base-perl libxml-sax-expat-perl libxml-sax-perl texinfo 升级了 0 个软件包,新安装了 28 个软件包,...
Libwww是W3C开发的一个开源HTTP库,它为开发者提供了在各种操作系统上实现HTTP协议的基础工具。本文将深入探讨名为“w3c-libwww-5.2.6.tar.gz”的UNIX版本的W3C Libwww工具包,包括其功能、应用以及如何在UNIX环境中...
1、文件内容:perl-libwww-perl-6.05-2.el7.rpm以及相关依赖 2、文件形式:tar.gz压缩包 3、安装指令: #Step1、解压 tar -zxvf /mnt/data/output/perl-libwww-perl-6.05-2.el7.tar.gz #Step2、进入解压后的目录,...
libcurl是一个多平台的开源库,专为各种网络协议(如HTTP、HTTPS、FTP等)提供客户端接口。它支持多种高级特性,如HTTPS证书验证、HTTP/2、管道、重定向、代理和身份验证。通过将libcurl集成到LWP中,Perl开发者可以...
libwww-perl(LWP)是Perl语言中一个强大的HTTP客户端库,它允许程序员创建能够发送HTTP请求并处理响应的程序。LWP提供了一套完整的API,包括处理各种HTTP方法(如GET、POST)、管理cookies、处理重定向等。 Ruby的...
- **依赖问题**:在某些情况下,你可能需要安装额外的依赖库,例如`libwww-perl`。这可以通过Homebrew或MacPorts等包管理器完成。 - **编译错误**:如果遇到编译错误,可能是因为编译器版本过新或过旧,或者缺少特定...
离线安装包,亲测可用
libwww-perl-6.04.tar同样是一个包含源码的tar文件,解压后通过适当的途径进行安装,就能在Perl环境中使用这个强大的网络交互库。 在Windows环境下,使用CYGWIN工具集,可以提供一个类Unix的命令行环境,这样就可以...
这些库主要用于支持图形绘制和图像处理等功能。 #### 准备工作 首先,需要创建一个新的仓库源文件 `dag.repo`,该文件将允许我们通过 yum 命令来安装所需的软件包。以下是具体的步骤: 1. **创建 dag.repo 文件**...
nagios-plugin-elastic...有关更多详细信息,请参阅--help有关相应的检查。 簇 集群状态 索引状态 在线节点数 裂脑检测 节点 打开文件描述符 JVM堆使用情况 线程池中被拒绝的工作单元 断路器跳闸 断路器内存大小限制
Munin ActiveMQ插件 在Munin中显示队列状态图。 要求 Perl模块 ... XML::Simple 插件安装 德比安 下载脚本 以root身份将queue_脚本下载到/usr/... apt-get install libwww-mechanize-perl apt-get install libxml-simpl
OneClickInstallUI http://multiymp.zq1.de/devel:languages:perl/perl-Fuse# and additionally you needzypper -n in make perl-libwww-perlmake install##用法 mkdir mntcurlwwwfs http://lsmod.de/bootcd/ mnt...
根据需要调整配置,优化性能,以及添加更多监控目标。 总结,安装和配置Smokeping需要了解Linux系统管理、软件包管理、CGI脚本和Apache服务器。这是一个涉及多方面技能的过程,但通过以上步骤,你可以在CentOS 6.5 ...
官方离线安装包,亲测可用。使用rpm -ivh [rpm完整包名] 进行安装
waka/2.0(可能指的是Apache HTTP Server的某个未来版本)可能会引入更多性能优化、安全增强和新的功能特性,以适应不断变化的Web环境。 五、Web架构的层次化模型 Web架构的核心理念是分层的客户端-服务器模型,...