Action disabled: source

Wget

GNU에서 만든 명령행 FTP 다운로드 프로그램이다. 오픈소스.

wget은 상호작용을 필요로 하지 않는 다운로드 프로그램으로 Web으로 부터 파일들을 가져올 수 있다. HTTP, HTTPS, FTP 프로토콜을 지원하며, HTTp proxy에서 데이터를 가져올 수도 있다.

wget이 상호작용을 필요로 하지 않는다는 것은, 백그라운드 상태에서 작동할 수 있음을 의미한다. 사용자는 로그인을 하지 않은 상태에서도 cron이나 Damon을 이용 wget을 실행시킬 수 있다. 또한 cookie, Form action을 지원해서 사용자 액션을 시뮬레이션 할 수도 있다.

wget은 HTML과 XHTML 페이지를 다운로드 받아서 로컬 파일시스템에 저장한다. 이때 파일이름과 디렉토리 구조까지를 그대로 로컬시스템에 구축함으로써, backup, mirror 사이트 구축등에 사용할 수도 있다. 또한 recursive 다운로드를 지원해서, 사이트 전체를 쉽게 내려받을 수 있다.

wget은 느리거나 불안정한 네트워크 환경에서도 매우 잘 작동하는 견고한 프로그램이다. 네트워크 환경이 불안해서 도중에 연결이 끊겼다면, 연결이 끊긴 시점부터 다운로드 받는 기능도 가지고 있다.

웹집보다 나을 수도 …

wget -r -nv -nH -N ftp://211.45.156.111/public_html/data/pages -P /var
wget -r -nv -nH -N ftp://id:[email protected]/html/data/pages/info.txt -P /home/www

옵션

  --recursive

Tells wget to recursively download pages, starting from the specified URL.

  --level=1

Tells wget to stop after one level of recursion. This can be changed to download more deeply, or set to 0 that means “no limit”

  --no-clobber

Skip downloads that would download to existing files

  --page-requisites

Tells wget to download all the resources (images, css, javascript, …) that are needed for the page to work.

  --html-extension

Adds ”.html” extension to downloaded files, with the double purpose of making the browser recognize them as html files and solving naming conflicts for “generated” URLs, when there are no directories with “index.html” but just a framework that responds dynamically with generated pages.

  --convert-links

After the download is complete, convert the links in the document to make them suitable for local viewing. This affects not only the visible hyperlinks, but any part of the document that links to external content, such as embedded images, links to style sheets, hyperlinks to non-HTML content, etc.

  --no-parent

Do not ever ascend to the parent directory when retrieving recursively.

  --domains=www.example.com

Set domains to be followed. DOMAIN-LIST is a comma-separated list of domains.

Avoiding imposed download limits Many web servers tend to limit the pages a user can download in a given amount of time, or the user-agents that can access given pages, etc. To avoid such limits, some extra options may be added.

  -U "Mozilla/5.0 (X11; U; Linux; en-US; rv:1.9.1.16) Gecko/20110929 Firefox/3.5.16"

Tells wget to use a fake user-agent, to emulate the one of a web browser (in this case, Firefox 3.5 on Linux)

  --wait=3

Tells wget to wait at least 3 seconds between retrievals.

  --random-wait

Tells wget to wait a random time between 0 and double the value specified with –wait between requests.

  -P prefix
--directory-prefix=prefix

Set directory prefix to prefix. The directory prefix is the directory where all other files and sub-directories will be saved to, i.e. the top of the retrieval tree. The default is . (the current directory).

예제

사이트 전체 받기

출처

 wget \
     --recursive \
     --no-clobber \
     --page-requisites \
     --html-extension \
     --convert-links \
     --restrict-file-names=windows \
     --domains website.org \
     --no-parent \
    --limit-rate=20k \
    --referer=125.209.222.141 \
         www.website.org/tutorials/html/
  1. -post-data=string
   --recursive: download the entire Web site.
   --domains website.org: don't follow links outside website.org.
   --no-parent: don't follow links outside the directory tutorials/html/.
   --page-requisites: get all the elements that compose the page (images, CSS and so on).
   --html-extension: save files with the .html extension.
   --convert-links: convert links so that they work locally, off-line.
   --restrict-file-names=windows: modify filenames so that they will work in Windows as well.
   --no-clobber: don't overwrite any existing files (used in case the download is interrupted and resumed).

사진 받기

wget -r -np --reject "*.txt" http://192.168.0.100/images
  • -r은 –recursive를 줄인 것.
  • -l (소문자 엘) 옵션을 사용하면 하위폴더의 단계를 정한다. 기본적으로 wget에서는 5단계까지 하위폴더의 모든 파일을 다운로드 함.
  • -np라는 옵션은 no-parent. recursive 옵션을 주고 실행할 때 부모 디렉토리의 파일을 다운로드 하지 말라는 뜻.
  • 이미지와 텍스트가 포함된 폴더라고 가정하면 –reject 옵션으로 txt 파일을 제외한다. 출처 ngee

여러 파일 받기

txt로 받을 파일의 주소(URL)을 한줄에 하나씩 넣은 뒤 '-i' 옵션을 사용하면 된다.

wget -i halo.txt
halo.txt
http://cdn.p30download.com/?b=p30dl-console&f=Halo.3.ODST.iMARS.DVD1_p30download.com.part1.rar
http://cdn.p30download.com/?b=p30dl-console&f=Halo.3.ODST.iMARS.DVD1_p30download.com.part2.rar
http://cdn.p30download.com/?b=p30dl-console&f=Halo.3.ODST.iMARS.DVD1_p30download.com.part3.rar
http://cdn.p30download.com/?b=p30dl-console&f=Halo.3.ODST.iMARS.DVD1_p30download.com.part4.rar
http://cdn.p30download.com/?b=p30dl-console&f=Halo.3.ODST.iMARS.DVD1_p30download.com.part5.rar
http://cdn.p30download.com/?b=p30dl-console&f=Halo.3.ODST.iMARS.DVD1_p30download.com.part6.rar
http://cdn.p30download.com/?b=p30dl-console&f=Halo.3.ODST.iMARS.DVD1_p30download.com.part7.rar
http://cdn.p30download.com/?b=p30dl-console&f=Halo.3.ODST.iMARS.DVD2_p30download.com.part1.rar
http://cdn.p30download.com/?b=p30dl-console&f=Halo.3.ODST.iMARS.DVD2_p30download.com.part2.rar
http://cdn.p30download.com/?b=p30dl-console&f=Halo.3.ODST.iMARS.DVD2_p30download.com.part3.rar
http://cdn.p30download.com/?b=p30dl-console&f=Halo.3.ODST.iMARS.DVD2_p30download.com.part4.rar
http://cdn.p30download.com/?b=p30dl-console&f=Halo.3.ODST.iMARS.DVD2_p30download.com.part5.rar
http://cdn.p30download.com/?b=p30dl-console&f=Halo.3.ODST.iMARS.DVD2_p30download.com.part6.rar
http://cdn.p30download.com/?b=p30dl-console&f=Halo.3.ODST.iMARS.DVD2_p30download.com.part7.rar

역링크