단일 특정 디렉토리에 wget 저장 페이지 파일 만들기

단일 특정 디렉토리에 wget 저장 페이지 파일 만들기

Firefox를 통해 웹페이지를 저장하면 다음과 같은 디렉터리 구조가 나타납니다.

.
├── Some Page/
└── Some Page.html

따라서 .html 파일과 이미지, 자바스크립트, CSS 등이 포함된 폴더가 있습니다.

wget동일한 결과(html + 단일 대형 폴더)를 얻기 위해 (또는 다른 명령줄 도구)를 사용할 수 있습니까?

편집: 여러 웹 페이지를 다운로드하고 때로는 각 페이지가 다운로드된 위치를 확인하는 것이 혼란스럽기 때문에 이것이 필요합니다.

답변1

문제를 완전히 이해하지 못할 수도 있지만 간단한 해결 방법은 해당 -r플래그를 사용하는 것입니다. 그래서:

wget -r www.site.com

최대 5단계 깊이의 항목은 재귀적으로 크롤링되고( -l NN이 최대 깊이인 경우 변경할 수도 있음) ./www.site.com/에 저장되며 기본적으로 크롤링한 URL이 다시 생성됩니다. 폴더 구조는 이 폴더 내에 있습니다. 그래서 당신은 끝납니다 :

.
├── www.site.com /
         └─────── pics
         |         └─── image1.jpg
         |         └─── image2.jpg
         └─────── index.html
         └─────── links.html

그러나 이렇게 하면 index.html 파일이 현재 폴더에 유지되지 않고 대신 사이트 폴더에 저장됩니다.

디렉토리 구조를 가지고 놀고 싶다면 경로를 줄이는 방법에 대한 정보가 있는 매뉴얼 페이지가 있습니다.

 Directory Options
       -nd
       --no-directories
           Do not create a hierarchy of directories when retrieving recursively.  With this option turned on, all files will get saved to the current directory, without clobbering (if a name shows up more than once, the filenames
           will get extensions .n).

       -x
       --force-directories
           The opposite of -nd---create a hierarchy of directories, even if one would not have been created otherwise.  E.g. wget -x http://fly.srk.fer.hr/robots.txt will save the downloaded file to fly.srk.fer.hr/robots.txt.

       -nH
       --no-host-directories
           Disable generation of host-prefixed directories.  By default, invoking Wget with -r http://fly.srk.fer.hr/ will create a structure of directories beginning with fly.srk.fer.hr/.  This option disables such behavior.

       --cut-dirs=number
           Ignore number directory components.  This is useful for getting a fine-grained control over the directory where recursive retrieval will be saved.

           Take, for example, the directory at ftp://ftp.xemacs.org/pub/xemacs/.  If you retrieve it with -r, it will be saved locally under ftp.xemacs.org/pub/xemacs/.  While the -nH option can remove the ftp.xemacs.org/ part,
           you are still stuck with pub/xemacs.  This is where --cut-dirs comes in handy; it makes Wget not "see" number remote directory components.  Here are several examples of how --cut-dirs option works.

                   No options        -> ftp.xemacs.org/pub/xemacs/
                   -nH               -> pub/xemacs/
                   -nH --cut-dirs=1  -> xemacs/
                   -nH --cut-dirs=2  -> .

                   --cut-dirs=1      -> ftp.xemacs.org/xemacs/
                   ...

           If you just want to get rid of the directory structure, this option is similar to a combination of -nd and -P.  However, unlike -nd, --cut-dirs does not lose with subdirectories---for instance, with -nH --cut-dirs=1, a
           beta/ subdirectory will be placed to xemacs/beta, as one would expect.

관련 정보