ÀÌ ÆäÀÌÁö´Â ÇѾç´ëÇб³ ÃÖÁ߹Π±³¼ö²²¼ ÀÛ¼ºÇÑ °ÍÀÔ´Ï´Ù.
[¿Â¶óÀÎ HTML ¹®¼ fetch ¹æ¹ý]
(1) Java ¾ð¾î¸¦ ÀÌ¿ëÇÏ´Â °æ¿ì, (2) Unix¿¡¼ C (C++)À» ÀÌ¿ëÇÏ´Â °æ¿ì, ±×¸®°í (3) Windows (95 or NT)¿¡¼ C (C++)À» ÀÌ¿ëÇÏ´Â °æ¿ì·Î ³ª´©¾î¼ ¼³¸íÇÑ´Ù.
ºÒÇàÈ÷µµ, ´Ù¸¥ ¾ð¾îÀÏ °æ¿ì´Â ³» ¼öÁØ¿¡¼´Â ´ëÃ¥¾øÀ½.
JDKÀÇ java.net package¿¡¼ Á¦°øµÇ´Â URLÀ̶ó´Â type°ú java.io package¿¡¼ Á¦°øµÇ´Â openStream, DataInputStream µîÀÇ method¸¦ È°¿ëÇÏ¸é µÈ´Ù.
°£´ÜÇÑ sample program (URLOpen.java)Àº ´ÙÀ½°ú °°´Ù. ÀÌ ÇÁ·Î±×·¥Àº ¾ßÈÄ (Yahoo) °Ë»ö¿£ÁøÀÇ URLÀ» ÁÖ°í ÇØ´ç Ȩ ÆäÀÌÁöÀÇ HTML ¼Ò½º¸¦ Çѹø¿¡ ÇÑ ÁÙ¾¿ °¡Á®¿Í¼ ȸ鿡 Ãâ·Â½ÃÄÑÁÖ°Ô µÈ´Ù.
import java.net.*; import java.io.*; class URLOpen { public static void main(String[] args) { try { URL yahoo = new URL("http://www.yahoo.com/"); DataInputStream dis = new DataInputStream(yahoo.openStream()); String inputLine; while ((inputLine = dis.readLine()) != null) { System.out.println(inputLine); } dis.close(); } catch (MalformedURLException me) { System.out.println("MalformedURLException: " + me); } catch (IOException ioe) { System.out.println("IOException: " + ioe); } } }
¸¸ÀÏ HTML source¸¦ ÈÀÏ¿¡ ÀúÀåÇÏ·Á¸é Java¿¡¼ Á¦°øÇÏ´Â output stream¿¡ ´ëÇÑ method¸¦ ÀÌ¿ëÇÏ¸é µÉ °ÍÀÌ´Ù.
% w3c http://www.hanyang.ac.krÀ» ½ÇÇàÇϸé ȸ鿡 ÁÖ¾îÁø URLÀÇ HTML source°¡ Ãâ·ÂµÈ´Ù. ÇÁ·Î±×·¥ ³»¿¡¼ ÀÌ°ÍÀ» ÀÌ¿ëÇÏ·Á¸é UnixÀÇ "system" callÀ» »ç¿ëÇÏ¸é µÉ °ÍÀÌ´Ù. Áï, ÇÁ·Î±×·¥³»¿¡ ´ÙÀ½°ú °°Àº ¹®ÀåÀ» ³¢¿ö³ÖÀ¸¸é µÈ´Ù.
system("w3c http://www.hanyang.ac.kr > outfile");ÀÌ callÀÇ °á°ú·Î ÇØ´ç HTML source°¡ outfile¿¡ ÀúÀåµÈ´Ù. À̶§, system ÇÔ¼öÀÇ argument´Â stringÀ̹ǷΠÀ§¿¡¼ ÁÖ¾îÁø http://www.hanyang.ac.kr ´ë½Å¿¡ ´Ù¸¥ URL¿¡ ´ëÇÑ HTML ¹®¼¸¦ °¡Á®¿À·Á¸é ´ÙÀ½°ú °°ÀÌ strcpy¿Í strcat ÇÔ¼ö¸¦ ÀÌ¿ëÇÑ´Ù.
char url[100], system_arg[150]; strcpy(url, "http://cse.hanyang.ac.kr/~jmchoi/cse418/proj3.html"); strcpy(system_arg, "w3c "); strcat(system_arg, url); strcat(system_arg, " > outfile"); system(system_arg);
ƯÈ÷, http://www.w3c.org/Library/Examples ¿¡ ¸î°¡Áö °£´ÜÇÑ ¿¹Á¦°¡ ³ª¿Í ÀÖÀ¸¹Ç·Î ÂüÁ¶Çϱ⠹ٶ÷.
#include <urlmon.h> char url[100], outfile[50]; strcpy(url, "http://cse.hanyang.ac.kr/~jmchoi/cse418/proj3.html"); strcpy(outfile, "out.txt"); URLDownloadToFile (NULL, url, outfile, 0, NULL);
´Ü, systemÀÇ path º¯¼ö¿¡ Visual C++ libÀÇ path¸¦ Ãß°¡½ÃÄÑ¾ß ÇÏ°í (Visual C++ ¼³Ä¡½Ã¿¡ ÀÚµ¿À¸·Î Ãß°¡µÇÁö¸¸ ¸¸ÀÏ µÇ¾îÀÖÁö ¾Ê´Ù¸é Á¦¾îÆÇÀÇ ½Ã½ºÅÛ¿¡¼ Ãß°¡½ÃÄÑ¾ß ÇÔ), compile½Ã¿¡ À§ÀÇ path¿¡ ÀÖ´Â urlmon.lib¸¦ Æ÷ÇÔ½ÃÄÑ¾ß ÇÔ. (Projects ¸Þ´ºÀÇ "setting" option¿¡¼ C/C++ Ç׸ñÀÇ library ¸®½ºÆ®¿¡ urlmon.lib¸¦ Ãß°¡½ÃÅ°¸é µÊ.)
Visual C++ 5.0 ÀÌÇÏÀÇ ¹öÀüÀ̳ª ´Ù¸¥ ÄÄÆÄÀÏ·¯ÀÇ °æ¿ì´Â URL¿¡ ´ëÇÑ library°¡ Á¦°øµÇ´ÂÁö Àß ¸ð¸£°ÚÁö¸¸ ¾Æ¸¶µµ ¾øÀ» °ÍÀ̶ó »ý°¢µÇ´Âµ¥, ÀÌ °æ¿ì´Â WWW Library¸¦ ¼³Ä¡ÇÏ¿© ÀÌ¿ëÇØ¾ß ÇÒ °Í °°À½.
³» °æÇèÀ¸·Î´Â Windows ȯ°æ¿¡¼ WWW Library¸¦ ÀÌ¿ëÇÏ´Â °ÍÀÌ Á» ¾î·Á¿î °Í °°À¸¹Ç·Î µÉ ¼ö ÀÖÀ¸¸é Visual C¸¦ ÀÌ¿ëÇÏ´Â °ÍÀÌ ¹Ù¶÷Á÷ÇÒ µíÇÔ.