我已经制作了一个批处理脚本,可以为我生成Google搜索网址(www.google.no/search?q=%topic%),现在我正在编写脚本这将下载每个URL上的内容。 问题是,Google搜索网址始终包含方程式符号,这在批处理脚本中无效。
我下载网址内容的代码:
setlocal ENABLEDELAYEDEXPANSION
::it's better to use the delayed expansion, because then the special characters lose their "special" behaviour, even carets and percent signs.
SET localfolder=%~dp0
SET logger="%~dp0"\%~n0.log
echo %date% %time% %~n0
del %logger%
set urlPathOuput=%~dp0
set indexFile=index.html
cd %localfolder%
for /f "tokens=*" %%1 in (urls.txt) do (
set "urlPath=%%~1" & call :download
)
goto :eof
:download
set urlPath=%urlPath: =%
set urlFileOutput=%urlPath%.log
set urlFileOutput=%urlFileOutput:/=_%
Echo %urlPath% "-"
wget "%urlpath%" > %localfolder%%urlFileOutput%
type %indexFile% > %localfolder%%urlFileOutput%
del %indexFile%
结果:
c:\ progge \ Scripts \ Web> set" urlPath = www.google.no/search?q=painting"
C:\ progge \脚本\网络与gt;设置 urlFileOutput = www.google.no/search?q=painting.log
C:\ progge \脚本\网络与gt;设置 urlFileOutput = www.google.no_search Q = painting.log
c:\ progge \ Scripts \ Web> Echo www.google.no/search?q=painting " - " www.google.no/search?q=painting " - "
c:\ progge \ Scripts \ Web> wget " www.google.no/search?q = painting" = painting.log 1> c:\ progge \ Scripts \ Web \ www.google.no_search?q
文件名,目录名或卷标语法不正确。c:\ progge \ Scripts \ Web>输入index.html = painting.log 1> c:\ progge \ Scripts \ Web \ www.google.no_search?q
文件名,目录名或卷标语法不正确。c:\ progge \ Scripts \ Web> del index.html
找不到c:\ progge \ Scripts \ Web \ index.html
网址必须包含等式符号才能生效。 我该如何解决这个问题?
答案 0 :(得分:1)
似乎不是urlpath的问题,而是%localfolder%%urlFileOutput%
路径的问题。
%localfolder%%urlFileOutput%
似乎是c:\progge\Scripts\Web\www.google.no_search?q=painting.log
。
首先,您需要用引号
将其括起来wget "%urlpath%" > "%localfolder%%urlFileOutput%"
但即便如此,它也不会起作用,因为它不是合法的路径名称
不允许在路径名中使用?
等字符。