【发布时间】:2016-06-09 23:06:20
【问题描述】:
我有兴趣通过在批处理文件的循环中运行 curl 语句来下载一堆网页。
网页以一个范围内的数字结尾,例如从 100 到 200,我想将每个页面下载为 html 文件。
当我运行以下程序时,程序冻结/抛出并出错。我怎样才能让它工作?
提前致谢!
@echo off
echo @echo pages will begin downloading... > ListOfPages.txt
SETLOCAL ENABLEDELAYEDEXPANSION
For /L %%A IN (100,1,200) do (
SET page="http://path/to/webpage/%%A"
SET destination="C:\path\to\file\sitenumber_%%A.html"
:: insert curl statements to new file
echo curl !page! -OutFile !destination! >> ListOfPages.txt
)
:: Loop through each line of new file and execute curl statement
For /F %%G in (C:\path\to\file\ListOfPages.txt) do (
WHAT GOES HERE???
)
【问题讨论】:
-
对于这种问题,我
echo 'curl ...',检查链接是否正常。然后echo到一个新文件并运行新文件。不要试图在一个脚本中完成。您需要一个检查点管道 -
这是个好建议。我现在正在尝试。
-
@llllllllllll 一旦我将 curl 语句发送到单独的文本文件,我该如何执行这些 curl 命令? ..我可以更新问题
-
坦率地说,我不知道如何在 Windows 中做到这一点。你能从 Windows 控制台运行
curl吗?然后,将您的 curl 列表保存为 bat 文件并从 Windows 控制台运行它。它应该工作,但我不确定。如果你使用 Cygwin,那么chmod u+x file; your_shell_name file -
@llllllllllll 我会尝试你的建议。不幸的是,我不能使用 Cygwin。我一直在处理 Windows 特定的命令。如果我可以使用 linux 命令,这将更容易。简单地说: curl "http://path/to/website/[100-200]" -o sitenumber_#1.html -s
标签: windows batch-file curl scripting