在for中用多个set的时候遇到点问题,来这里一查才知道是变量延迟的问题,现在明白了。献上一段批量下载《批处理室经典帖子分类索引》中帖子的批处理
@echo off
echo.
echo 需要grep/sed/ConvertZ 8.02/wget等软件配合
echo 请到http://gnuwin32.sourceforge.net/下载上面几个软件并安装
echo.
pause
set Wget_Path=C:\Program Files\GnuWin32\bin
path %Wget_path%;E:\software\小工具\ConvertZ 8.02;%path%
wget "http://www.cn-dos.net/forum/viewthread.php?tid=27667&action=printable" -O index.html
rem utf8编码转gbk
start /wait ConvertZ /i:utf8 /o:gbk /f:s index.html
grep ">可打印版本<" index.html >tmp1.txt
grep -o tid=* tmp1.txt >tmp2.txt
grep -o * tmp2.txt >tmp3.txt
md bat
cd bat
md images
cd images
md default
cd default
wget http://www.cn-dos.net/forum/images/default/logo.gif
cd ..
cd ..
for /f %%f in (..\tmp3.txt) do (
IF NOT EXIST viewthread_%%f.html (
wget "http://www.cn-dos.net/forum/viewthread.php?tid=%%f&action=printable" -O viewthread_%%f.html
start /wait ConvertZ /i:utf8 /o:gbk /f:s viewthread_%%f.html
grep "打印本页" viewthread_%%f.html >tmp1.txt
sed "s/<b>标题: <\/b>//g;s/ <a.*//g" tmp1.txt >tmp2.txt
for /f %%i in (.\tmp2.txt) do rpl "<title>中国DOS联盟论坛 - Powered by Discuz! Board</title>" "<title>%%i</title>" viewthread_%%f.html
)
)
move /Y ..\index.html
然后用工具替换一下index.html中的url地址就行了。