无聊时写的一个小工具,代码还是很繁杂。用到了外部工具curl.exe,测试成功率90+,出错原因可能是无此单词,或者文本提取错误。
直接运行,输入要查的单词,会输出单词的词性、释义、以及例句。- @echo off&title English Online
- for %%a in (a n prep vt vi adv adj ad conj) do set %%a.=a
- for %%i in (a.[Z] vi.[W] vt.vi. n.[C]) do set "%%i=a"
- :loop
- cls&set "word="
- echo.&set/p word= English Online:
- for %%a in (on off) do if "%word%" equ "%%a" goto :next
- echo %word%|findstr/i "^[a-z]*$">nul||goto loop
- :next
- curl "http://www.baidu.com/baidu?ie=gb2312&cl=3&ct=1048576&word=%word%" -o tmp.txt
- cls&more +100 tmp.txt>temp.txt
- del tmp.txt&echo.&echo [%word%]
- for /f "delims=" %%a in (temp.txt) do (
- set "str=%%a"
- setlocal enabledelayedexpansion
- set "str=!str:*]=!"&set "str=!str:*]=!"
- set "str=!str:</div><div class=!"&set "str=!str:pcixin>=!"
- set "str=!str:pexplain>=!"&set "str=!str:peng><span id=!"
- set "str=!str:dropdownid>=!"&set "str=!str:<font class=!"
- set "str=!str:engi>=!"&set "str=!str:</font>=!"
- set "str=!str:</span>=!"&set "str=!str:pchi><span id=!"
- set "str=!str:</div><div =!"&set "str=!str:<==!"&set "str=!str:>==!"
- set "str=!str:^)=!"&set "str=!str:^(=!"&set "str=!str:"=!"
- call :lp "!str!"
- endlocal
- del temp.txt 2>nul&pause>nul&goto :loop
- )
- :lp
- for /f "tokens=1* delims==" %%a in ("%~1") do (
- set "var=%%a"
- if /i "!var!" equ "/body" echo.&echo ERROR&goto :eof
- if /i "!var:~,4!" equ "/div" goto :eof
- if defined !var! echo.
- for /l %%a in (0 1 9) do if "!var:~,1!" equ "%%a" echo.
- echo !var!
- if "%%b" neq "" call :lp "%%b"
- )
- goto :eof
复制代码 第三方命令行工具curl.exe下载地址:
http://bbs.bathome.net/thread-3981-1-1.html
-------------------------------------------------------------------------------------------------------------------------------------
调用外部工具wfr.exe简化代码。使用wget.exe下载html网页代码。
添加了备份功能,会在D盘生成一个名为word的文件夹,里面存放查阅过的单词。- @echo off
- if not exist d:\word\ md d:\word\
- :loop
- setlocal
- cls&echo.&echo.
- set/p word= English online:
- if not defined word endlocal&goto loop
- if exist "d:\word\%word%.txt" type "d:\word\%word%.txt"&pause>nul&endlocal&goto loop
- (echo.&echo [%word%]&echo.)>"d:\word\%word%.txt"
- wget -O tmp.txt "http://www.baidu.com/baidu?ie=gb2312&cl=3&ct=1048576&word=%word%" -q
- title English online
- more +100 tmp.txt>tmp&move /y tmp tmp.txt
- wfr tmp.txt /rnnlic:"(以上结果.*|.*>\]</div>|<\/(font|div|span)>)" /t
- wfr tmp.txt /r:"(<div class=p(cixin|explain|eng|chi)>|<span id=dropdownid>|<(font class=engi|br)>)" /t
- type tmp.txt|wfr /r:"\d+\." /t:"\r\n\r\n\0"|wfr /r:"(([a-z]+|\a)(\.|\?))" /t:"\0\n"|wfr /r:"[A-Z]{1,}(\s|\a)+" /t:"\n\0">>"d:\word\%word%.txt"
- type "d:\word\%word%.txt"&del tmp.txt
- endlocal
- pause>nul
- goto loop
复制代码 第三方命令行工具wget.exe和wfr.exe下载地址:
http://bbs.bathome.net/thread-3981-1-1.html |