網頁抓取和ftp訪問是目前很常見的一個應用需要,無論是搜索引擎的爬蟲,分析程序,資源獲取程序,WebService等等都是需要的,自己" />

欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

HTTP/FTP客戶端開發庫:libwww、libcurl、libfe

系統 2012 0
<iframe align="center" marginwidth="0" marginheight="0" src="http://www.zealware.com/csdnblog336280.html" frameborder="0" width="336" scrolling="no" height="280"></iframe>


網頁抓取和ftp訪問是目前很常見的一個應用需要,無論是搜索引擎的爬蟲,分析程序,資源獲取程序,WebService等等都是需要的,自己開發抓取庫當然是最好了,不過開發需要時間和周期,使用現有的Open source程序是個更好的選擇,一來別人已經寫的很好了,就近考驗,二來自己使用起來非??焖伲齺碜约哼€能夠學習一下別人程序的優點。

閑來無事,在網上瀏覽,就發現了這些好東西,特別抄來分享分享。主要就是libwww、libcurl、libfetch 這三個庫,當然,還有一些其他很多更優秀庫,文章后面會有簡單的介紹。

【libwww】
官方網站: http://www.w3.org/Library/
更多信息: http://www.w3.org/Library/User/
運行平臺:Unix/Linux,Windows

以下資料來源: 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】

官方網站: http://curl.haxx.se/libcurl
更多特點: http://curl.haxx.se/docs/features.html
運行平臺:Unix/Linux,Windows(Windows上貌似也有實現)

以下資料來源: http://blog.csdn.net/hwz119/archive/2007/04/29/1591920.aspx

Libcurl 為一個免費開源的,客戶端 url 傳輸庫,支持 FTP , FTPS , TFTP , HTTP HTTPS , GOPHER , TELNET , DICT FILE LDAP ,跨平臺,支持 Windows , Unix Linux 等,線程安全,支持 Ipv6 。并且易于使用。

http://curl.haxx.se/libcurl/

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

上面編譯的是 libcurl dll ,使用 OpenSSL Dll 版本和 Zlib Dll 版本。如果沒有,可以從 www.openssl.org 或者 http://www.zlib.net/ 下載。

如果需要編譯其他版本,可查看 Makefile.vc6 ,設定相應的 CFG 參數即可。

商業軟件使用 libcurl 時,只需要包含其 copywrite 聲明即可。

Sample

#include stdio.h >
#include
" ../curl-7.14.0/include/curl/curl.h "
#pragma comment(lib,"../curl-7.14.0/lib/libcurl_imp.lib")

int main( 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);
}
return 0 ;
}

【libfetch】
官方網站: http://libfetch.darwinports.com/
更多信息: http://www.freebsd.org/cgi/man.cgi?query=fetch&sektion=3
運行平臺:BSD

以下資料來源: http://bbs.chinaunix.net/viewthread.php?tid=105809

前幾天無雙老大在FB版介紹了一下CU的巨猛的法老級灌水大師,小弟于是說要編個程序自動來灌,哈哈昨晚有所突破,找到一個很好的庫,先介紹給各位大魚小蝦們,不過可別真的拿它來灌水啊,否則我被這里的班長們砍死以后的冤魂可要來算帳的喔!
這是在FreeBSD里找到的一個庫:libfetch,源代碼在/usr/src/lib/libfetch里,它對http和ftp協議進行了封裝,提供了一些很容易使用的函數,因為昨天剛看到,還沒仔細研究,我試了一個用http取網頁的函數,示例如下:
#include stio.h >
#include
#include

#include
" fetch.h "

const char * myurl = " http://qjlemon:aaa@192.169.0.1:8080/test.html " ;

main()
{
FILE
* fp;
char buf[ 1024 ];

fp
= fetchGetURL(myurl, "" ;
if ( ! fp){
printf(
" error:%s " ,fetchLastErrString);
return 1 ;
}
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函數,想要灌水就得用這個喲!哈哈哈!

【其他相關HTTP/FTP客戶端庫】
資料來源: http://curl.haxx.se/libcurl/competitors.html

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:

libcurl (MIT)

    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!

libghttp (LGPL)

    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.

libwww ( W3C license ) comparison with libcurl

    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.

libferit (GPL)

    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."

neon (LGPL)

    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.

libsoup (LGPL) comparison with libcurl

    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.

mozilla netlib (MPL)

    Handles URLs, protocols, transports for the Mozilla browser.

mozilla libxpnet (MPL)

    Minimal download library targeted to be much smaller than the above mentioned netlib. HTTP and FTP support.

wget (GPL)

    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.

libfetch (BSD)

    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.

HTTP Fetcher (LGPL)

    " a small, robust, flexible library for downloading files via HTTP using the GET method. "

http-tiny (Artistic License)

    " a very small C library to make http queries (GET, HEAD, PUT, DELETE, etc.) easily portable and embeddable "

XMLHTTP Object also known as IXMLHTTPRequest (part of MSXML 3.0)

    (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 (GPL)

    QHttp is a class in the Qt library from Troll Tech. Seems to be restricted to plain HTTP. Supports GET, POST and proxy. Asynchronous.

ftplib (GPL)

    " 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."

ftplibpp (GPL)

    A C++ library for "easy FTP client functionality. It features resuming of up- and downloads, FXP support, SSL/TLS encryption, and logging functionality."

GNU Common C++ library

    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

HTTPClient (LGPL)

    Java HTTP client library.

Jakarta Commons HttpClient (Apache License)

    A Java HTTP client library written by the Jakarta project.



HTTP/FTP客戶端開發庫:libwww、libcurl、libfetch 以及更多


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦?。。?/p>

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 精品国产第一国产综合精品 | 国产在线精品一区二区高清不卡 | 嫩草99| 亚洲午夜大片 | 大逼逼影院 | 欧美视频网站在线观看 | 麻豆av在线播放 | 亚洲国产精品成 | 久久久一区二区三区视频 | 色欲AV久久一区二区三区 | 国产人妻精品无码AV在线浪潮 | 国产91在线观看 | 日本高清香蕉色视频在线观看 | 亚洲欧美日韩中文字幕在线不卡 | 精品一区二区久久久久久久网站 | 一区二区三区日 | 亚洲精品免费在线观看 | 日韩在线观看中文字幕 | 草草影院国产第一页 | 仇爱电视剧泰剧在线观看免费播放 | 欧美精品免费xxxxx视频 | 亚洲美女视频 | 黄视频网站免费看 | 国产啪| 亚洲精品中文字幕大岛优香 | 国产精品第三页在线看 | 亚洲国产精品网站 | 在线中文一区 | 日韩www| 天天影院成人免费观看 | 成人国产在线观看 | 色图综合| 国产超碰人人做人人爱 | 欧美日韩在线视频观看 | 91成人在线 | 欧美在线观看a | 宅男lu666噜噜噜在线观看 | 亚洲日本视频 | 国产日产亚洲欧美综合另类 | 私房色播 | 大伊香蕉在线观看视频 wap |