1

系统信息:Windows 7、GNU Wget 1.11.4、Python 2.6

问题:

我正在运行一个触发 wget 快捷方式的 python 脚本,问题是 wget(即使纯粹在 exe 命令行中运行)会切断“&”。例如,当我运行下面的代码时,这就是我得到的:

C:\Program Files\GnuWin32\bin>wget.exe http://www.imdb.com/search/title?genres=action&sort=alpha,asc&start=51&title_type=feature

SYSTEM_WGETRC = c:/progra~1/wget/etc/wgetrc syswgetrc = C:\Program Files\GnuWin32/etc/wgetrc

--2013-01-18 12:48:43-- http://www.imdb.com/search/title?genres=action正在解析 www.imdb.com... 72.21.215.52 连接到 www.imdb.com |72.21.215.52|:80... 失败:连接被拒绝。

=alpha,asc系统找不到指定的文件。

系统找不到文件 51. 'title_type' 不是内部或外部命令、可运行程序或批处理文件。

如您所见,wget 将 '&' 之前的所有文本都视为有问题的 URL,而 windows 将后半部分作为新命令。

必须有某种方法允许 wget 将整个字符串捕获为 URL。

提前致谢。

编辑:当我在命令行中用括号调用命令时,它工作得很好,但是,当我通过 python 运行脚本时:

subprocess.Popen(['start /B wget.lnk --directory-prefix=' + output_folder + ' --output-document=' + output_folder + 'this.html "http://www.imdb.com/search/title?genres=action&sort=alpha,asc&start=51&title_type=feature"'], shell=True)

我收到以下错误:

SYSTEM_WGETRC = c:/progra~1/wget/etc/wgetrc

syswgetrc = C:\Program Files (x86)\GnuWin32/etc/wgetrc

“http://www.imdb.com/search/title?genres=action&sort=alpha,asc&start=51&title_type=feature”:不支持的方案。

4

1 回答 1

1

切断 URL 的不是 Wget,而是命令解释器,它用于&分隔两个命令,类似于;. 这由=alpha,ascThe system cannot find the file specified.下一行的错误指示。

为防止这种情况发生,请引用整个 URL:

wget.exe "http://www.imdb.com/search/title?genres=action&sort=alpha,asc&start=51&title_type=feature"
于 2013-01-18T11:08:47.480 回答