本文共 2369 字,大约阅读时间需要 7 分钟。
我需要将文件下载到/ tmp / cron_test /。 我的代码是
wget --random-wait -r -p -nd -e robots=off -A".pdf" -U mozilla http://math.stanford.edu/undergrad/
那么是否有一些参数来指定目录?
从手册页:
-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/
(长格式)。 另请注意,如果目录不存在,则会创建该目录。
试试这个方法 -
import ospath = 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))
-O是指定要下载的文件的路径的选项。
wget-O /path/to/folder/file.ext
-P是将在目录中下载文件的前缀
wget-P /path/to/folder
确保您所下载的内容的URL正确无误。 首先,带有字符的网址?
这样就无法解析和解决。 这将混淆cmd行并接受未解析为源URL名称的任何字符作为要下载的文件名。
例如:
wget "sourceforge.net/projects/ebosse/files/latest/download?source=typ_redirect"
将下载到名为?source=typ_redirect
的文件中。
如您所见,了解一两个关于URL的内容有助于理解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 "/filename.extension"
在源网址之后。
在我的情况下,这导致下载ISO并将其存储为isofile.iso
下的二进制文件,希望能够安装。
man wget:-O file --output-document = file
wget "url" -O /tmp/cron_test/
“-P”是正确的选择,请继续阅读以获取更多相关信息:
wget -nd -np -P / dest / dir --recursive
为方便起见,手册页中的相关摘要:
-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.
转载地址:http://zrogj.baihongyu.com/