返回列表 发帖

[网络工具] 批处理在线学习英语

无聊时写的一个小工具,代码还是很繁杂。用到了外部工具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 :eofCOPY
第三方命令行工具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 loopCOPY
第三方命令行工具wget.exe和wfr.exe下载地址:
http://bbs.bathome.net/thread-3981-1-1.html
3

评分人数

心绪平和,眼藏静谧。

看来pusofalse又研究了新领域了,呵呵,不过总觉得这种代码实际意义并不大,只是如何自动登录网页并进行搜索的方法值得借鉴。
***共同提高***

TOP

我觉得用google可能更好些
http://www.google.cn/language_tools?hl=zh-CN
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

下来试试!
值得学习啊

TOP

不行!!!!
测试不成功

TOP

回复 5楼 的帖子

请把出错信息贴上来
心绪平和,眼藏静谧。

TOP

回复 5楼 的帖子

Q: 为什么不行啊?
A: 去电线杆上找个老军医的手机,他是专治+包治这个的。如果治疗周期较长,建议列出你的测试环境、测试用例、出错信息,供大家帮助你解决问题。
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

回复 3楼 的帖子

google 百度 雅虎 这三家我都试验过了,curl在download的时候会保存为默认的编码格式,google是UTF-8,有用wfr进行编码转换,可是不管怎么转换都会丢弃信息,所以就用了百度,不知curl有无编码转换的功能。
心绪平和,眼藏静谧。

TOP

curl dict://dict.org/d:computer

TOP

借用est写过的下载网页vbs代码
感觉vbs功能还是很强大
::::::::::::::::::::::::::::::::::::::::::::::::
::[用法] 保存为dict.bat于当前路径后,命令行下格式: dict word
::::::::::::::::::::::::::::::::::::::::::::::::
@echo off||author:plp626&<%~fs0 more +7>%tmp%\gtxt.vbs
set "url=http://www.baidu.com/baidu?ie=gb2312&cl=3&ct=1048576&word=%1"
cscript //NoLogo //e:vbscript %tmp%\gtxt.vbs "%url%"|more +4|findstr/v "Dr\.eye Baidu"|findstr .
exit/b
'         
Set oDOM = WScript.GetObject(WScript.Arguments(0))
do until oDOM.readyState = "complete"
WScript.sleep 100
loop
WScript.echo oDOM.documentElement.outerTextCOPY
论坛把代码的空行竟然过滤了!!

[ 本帖最后由 plp626 于 2008-9-11 02:21 编辑 ]
3

评分人数

TOP

回复 9楼 的帖子

plp兄的代码果然高深,希望赐教一二。
心绪平和,眼藏静谧。

TOP

代码空行
测试COPY
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

回复 10楼 的帖子

加了code标签以后就不会过滤空行了吧,见12楼的测试。
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

其实只要在新的方面有点成绩了,慢慢弄嘛。找到更多得简便。

TOP

下了,很好用。
只能从good good study开始学起了,英语基本忘了。

TOP

返回列表