如何用wget指定位置?

时间:2009-07-03 09:19:44

标签: wget

我需要将文件下载到/ tmp / cron_test /。我的wget代码是

wget --random-wait -r -p -nd -e robots=off -A".pdf" -U mozilla http://math.stanford.edu/undergrad/

那么是否有一些参数来指定目录?

6 个答案:

答案 0 :(得分:826)

从手册页:

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

因此,您需要在命令中添加-P /tmp/cron_test/(简短格式)或--directory-prefix=/tmp/cron_test/(长格式)。另请注意,如果目录不存在,则会创建该目录。

答案 1 :(得分:319)

-O是指定要下载的文件路径的选项。

wget <file.ext> -O /path/to/folder/file.ext

-P是将在目录

中下载文件的前缀
wget <file.ext> -P /path/to/folder

答案 2 :(得分:6)

确保您下载的内容的网址正确无误。首先,无法解析和解析具有?等字符的网址。这会使cmd行混淆并接受任何未解析为源URL名称的字符作为您要下载的文件名。

例如:

wget "sourceforge.net/projects/ebosse/files/latest/download?source=typ_redirect"

将下载到名为?source=typ_redirect

的文件中

正如您所看到的,了解有关网址的一两件事有助于理解wget

我从一个hirens磁盘启动,只有Linux 2.6.1作为资源(导入操作系统不可用)。解决我将ISO下载到物理硬盘驱动器上的问题的正确语法是:

wget "(source url)" -O (directory where HD was mounted)/isofile.iso" 

可以通过查找wget下载到名为index.html的文件(默认文件)的位置来确定正确的URL,并且具有您需要显示的文件的正确大小/其他属性以下命令:

wget "(source url)"

一旦该URL和源文件正确并且正在下载到index.html,您就可以停止下载( ctrl + z )并更改输出文件使用:

-O "<specified download directory>/filename.extension"

在源网址之后。

在我的情况下,这导致下载ISO并将其存储为isofile.iso下的二进制文件,希望能够安装。

答案 3 :(得分:2)

男人wget:  -O文件        --output文档=文件

wget "url" -O /tmp/cron_test/<file>

答案 4 :(得分:1)

“-P”是正确的选项,请继续阅读以获取更多相关信息:

wget -nd -np -P / dest / dir --recursive http://url/dir1/dir2

手册页中的相关摘要,为方便起见:

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

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


   -np
   --no-parent
       Do not ever ascend to the parent directory when retrieving recursively.  This is a useful option, since it guarantees that only the files below a certain hierarchy will be downloaded.

答案 5 :(得分:-11)

尝试这种方法 -

import os
path = raw_input("enter the url:")
fold = raw_input("enter the folder:")
os.system('wget -r -nd -l1 -P %s --no-parent -A mp3 %s'%(fold, path))
相关问题