[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

VBS如打开百度搜索,其中关键字从配置文件提取?

Set WshShell=wscript.createobject("Wscript.Shell")
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate("about:blank")
objIE.document.parentwindow.clipboardData.SetData "text","关键字"
objIE.Quit
set ierunner = CreateObject("wscript.shell")
ierunner.run "cmd /c start iexplore http://www.baidu.com",0
wscript.sleep 3000
WshShell.Sendkeys("^v")
ierunner.sendkeys "{ENTER}"
高手 帮我改下 ~
如打开百度搜索 其中关键字从配置文件提取` 一行为一个关键字 (中文)

打开百度搜索k.txt的第一行的批处理:
  1. @set /p k=<k.txt
  2. @start iexplore "http://www.baidu.cn/s?wd=%k%"
复制代码

TOP

回版主

我是想要个VBS 打开百度输入关键字 然后回车

关键字是从配置文件sf.ini中随机输入 一行为一个关键字 ,N行随机输入

TOP

  1. Option Explicit
  2. OpenBaidu GetRandomLine("k.txt")
  3. Sub OpenBaidu(sKey)
  4.         Dim oShell
  5.         Set oShell = CreateObject("WScript.Shell")
  6.         oShell.Run "iexplore http://www.baidu.cn/s?wd=" + sKey
  7.         Set oShell = Nothing
  8. End Sub
  9. Function GetRandomLine(sFile)
  10.         Dim oFso, oFile, iLineNo
  11.         Set oFso = CreateObject("Scripting.FileSystemObject")
  12.         Set oFile = oFso.OpenTextFile(sFile)
  13.         iLineNo = GetRandom(GetFileLineCount(sFile))
  14.         Do Until oFile.AtEndOfLine
  15.                 If iLineNo = oFile.Line Then
  16.                         GetRandomLine = oFile.ReadLine
  17.                         Exit Do
  18.                 Else
  19.                         oFile.SkipLine
  20.                 End If        
  21.         Loop
  22.         oFile.Close
  23.         Set oFile = Nothing
  24.         Set oFso = Nothing        
  25. End Function
  26. Function GetFileLineCount(sFile)
  27.         Dim oFso, oFile
  28.         Set oFso = CreateObject("Scripting.FileSystemObject")
  29.         Set oFile = oFso.OpenTextFile(sFile)
  30.         While Not oFile.AtEndOfLine
  31.                 oFile.SkipLine        
  32.         Wend
  33.         GetFileLineCount = oFile.Line
  34.         oFile.Close
  35.         Set oFile = Nothing
  36.         Set oFso = Nothing
  37. End Function
  38. Function GetRandom(n)
  39.         Randomize
  40.         GetRandom = Int(Rnd * n + 1)
  41. End Function
复制代码

[ 本帖最后由 rat 于 2008-11-23 15:40 编辑 ]

TOP

非常感谢 版主 虽然不是我想要的 但是还要 感谢你
@echo off
setlocal enableDelayedExpansion
for /f "delims=" %%i in (sh.ini) do set/a n+=1
set/a R=%random%%%n
for /f "delims=" %%i in ('more +%R% sh.ini') do set "a=%%i"&goto :next
:next
if "%~1" equ "" start/b cmd /c "%~fs0 a>>a.vbs"
echo Set WshShell=wscript.createobject("Wscript.Shell")
echo Set objIE = CreateObject("InternetExplorer.Application")
echo objIE.Navigate("about:blank")
echo objIE.document.parentwindow.clipboardData.SetData "text","%a%"
echo objIE.Quit
echo set ierunner = CreateObject("wscript.shell")
echo ierunner.run "cmd /c start iexplore http://www.baidu.com",0
echo wscript.sleep 4000
echo WshShell.Sendkeys("^v")
echo ierunner.sendkeys "{ENTER}"

这才是我想要的
也请版主帮我修改一下

TOP

我是想要个VBS 打开百度输入关键字 然后回车

关键字是从配置文件sf.ini中随机输入 一行为一个关键字 ,N行随机输入

原帖由 xtavvf 于 2008-11-23 22:59 发表
非常感谢 版主 虽然不是我想要的 但是还要 感谢你


……,写剪切板再Sendkeys?思路不好。我给出的代码是完全符合你的要求的。

TOP

前此天在问问上写过一个,也是类似于重复获取文件行数,FSO每次都要去读文件,太麻烦,就读到内存,用正则子集分行,速度快一些,改过来看看
  1. Dim objIE,Lines
  2. CreateIe
  3. RegExpTest(ReadText("sh.ini"))
  4. Function RegExpTest(string)
  5. msgbox lines
  6.    Set RegEx1=New RegExp
  7.    RegEx1.Pattern="(.*)(\n)"     
  8.    RegEx1.IgnoreCase=True
  9.    RegEx1.Global=True      
  10.    Set A=RegEx1.Execute(string)
  11.    Do
  12.       Set AA=A(Int((Lines-1)*rnd))
  13.       BB=AA.SubMatches(0)
  14.       SendWeb BB
  15.       WScript.Sleep 5000
  16.    Loop
  17. End Function
  18. Sub SendWeb(sText)
  19. With objIe
  20. .Navigate "www.baidu.com"
  21. Do While (.Busy)
  22. Wscript.Sleep 200
  23. Loop
  24. .Visible=1
  25. .Document.All.wd.Value=sText
  26. .Document.All.sb.click
  27. End With
  28. End Sub
  29. Function CreateIe
  30. Set objIE=WScript.CreateObject("InternetExplorer.Application","UE_")
  31. objIE.Navigate("about:blank")
  32. End Function
  33. Function ReadText(FilePath)
  34. Dim Fso,Rso
  35. Set Fso=CreateObject("Scripting.FileSystemObject")
  36. Set Gso=Fso.GetFile(FilePath)
  37. Set Rso=Gso.OpenAsTextStream(1)
  38. ReadText=Rso.ReadAll
  39. Lines=Rso.Line
  40. Set Fso=Nothing
  41. End Function
  42. Sub UE_OnQuit()
  43. WScript.Quit
  44. End Sub
复制代码

TOP

返回列表