标题: [文本处理] 批处理命令findstr返回结果为何出错? [打印本页]
作者: zahirll 时间: 2012-8-26 04:05 标题: 批处理命令findstr返回结果为何出错?
本帖最后由 zahirll 于 2012-8-26 21:03 编辑
1.txt里面的内容是:baidu.com
www.xxx.com
我想要达到搜索有结果的就返回域名到2.txt
像上面两个域名baidu.com肯定是有结果的,www.xxx.com是无结果的。
遇到两个问题就是不管有没搜到结果都返回到2.txt
还有一个就是 findstr行2太长。。
请高手帮我修改一些,万分感谢。- @echo off
- more +9 "%~f0" >GetUrlText.vbs
- type nul >2.txt
- for /f %%a in (1.txt) do (
- echo 正在检测:%%a
- cscript //nologo GetUrlText.vbs "http://baidu.com/ns?word=site:%%a" | findstr "不存在" && >>2.txt echo,%%a
- )
- goto :eof
-
-
- strURL=WScript.Arguments(0)
- WScript.Echo strURL
- Set objXmlHttp = CreateObject("Microsoft.XMLHTTP")
- objXmlHttp.Open "GET",strURL,0
- objXmlHttp.Send()
- Set objStream = CreateObject("ADODB.Stream")
- objStream.Mode = 3
- objStream.Type = 1
- objStream.Open()
- objStream.Write(objXmlHttp.responsebody)
- objStream.Position = 0
- objStream.Type = 2
- objStream.Charset = "utf-8"
- strText = objStream.Readtext
- WScript.Echo strText
复制代码
作者: apang 时间: 2012-8-26 10:16
- @echo off
- set "url=http://www.baidu.com/s?tn=baidusite&word=site"
- more +9 "%~f0" >a.vbs
- for /f %%a in (1.txt) do (
- echo 正在检测:%%a
- cscript //nologo a.vbs "%url%:%%a"|find "抱歉,没有找到">nul||>>2.txt echo %%a
- )
- del a.vbs&pause&goto :eof
-
- strURL=WScript.Arguments(0)
- WScript.Echo strURL
- Set objXmlHttp = CreateObject("Microsoft.XMLHTTP")
- objXmlHttp.Open "GET",strURL,0
- objXmlHttp.Send()
- Set objStream = CreateObject("ADODB.Stream")
- objStream.Mode = 3
- objStream.Type = 1
- objStream.Open()
- objStream.Write(objXmlHttp.responsebody)
- objStream.Position = 0
- objStream.Type = 2
- objStream.Charset = "utf-8"
- strText = objStream.Readtext
- WScript.Echo strText
复制代码
作者: zahirll 时间: 2012-8-26 14:58
代码有点问题,有些存在上面关键字的也输出了
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |