Internet explorer 从文本文件读取域并在浏览器中打开
我在一个文本文件中列出了大约100多个网页,我必须对这些网页进行分析。复制和粘贴可能非常繁忙 我认为在一个脚本中运行一个文本文件将非常有效,该脚本将一次打开一个域,在我关闭IE之后,它将打开下一个域 如果可能的话,更新列表并删除访问过的列表,但是如果有很多工作,我可以将其传递 假设有:Internet explorer 从文本文件读取域并在浏览器中打开,internet-explorer,powershell,vbscript,dns,Internet Explorer,Powershell,Vbscript,Dns,我在一个文本文件中列出了大约100多个网页,我必须对这些网页进行分析。复制和粘贴可能非常繁忙 我认为在一个脚本中运行一个文本文件将非常有效,该脚本将一次打开一个域,在我关闭IE之后,它将打开下一个域 如果可能的话,更新列表并删除访问过的列表,但是如果有很多工作,我可以将其传递 假设有: yahoo.com google.com microsoft.com PowerShell它实际上不起作用,因为我刚刚跳入了PowerShell $domain = Get-Content ".\list.tx
yahoo.com
google.com
microsoft.com
PowerShell它实际上不起作用,因为我刚刚跳入了PowerShell
$domain = Get-Content ".\list.txt"
ForEach($element in $domain){
$url = "$domain"
$ie = new-object -com "InternetExplorer.Application"
$ie.Navigate($url)
}
VBScript
这
工作,但一次打开所有页面。如果有那么多URL,可能会崩溃。我怎样才能控制它
Set fso = CreateObject("Scripting.FileSystemObject")
Set listFile = fso.OpenTextFile("list.txt")
Set WshShell = WScript.CreateObject("WScript.Shell")
Dim fso
do while not listFile.AtEndOfStream fName = listFile.ReadLine()
Return = WshShell.Run("iexplore.exe " & fName, 1)
loop
注意:更新为包含删除已访问URL的行,并将IE窗口置于最前面 这将通过PowerShell实现:
#VB assembly needed for function to bring IE to front
Add-Type -Assembly "Microsoft.VisualBasic"
$domain = Get-Content "c:\temp\list.txt"
ForEach($url in $domain){
#Start IE and make it visible
$ie = new-object -com "InternetExplorer.Application"
$ie.Visible = $true
#Bring the IE window to the front
$ieProc = Get-Process | ? { $_.MainWindowHandle -eq $ie.HWND }
[Microsoft.VisualBasic.Interaction]::AppActivate($ieProc.Id)
#Navigate to the URL
$ie.Navigate($url)
#Sleep while IE is running
while($ie.visible){
start-sleep -s 1
}
#Delete the URL from the file
(type c:\temp\list.txt) -notmatch "^$url$" | out-file c:\temp\list.txt
}
如果要在脚本完成之前停止脚本,请转到PowerShell窗口并将其关闭或按Ctrl+C键。您的VBScript将失败,因为您没有正确使用脚本。第三个参数bWaitOnReturn必须设置为True。如
Const csFSpec = "31144615.txt"
Dim goFS : Set goFS = CreateObject("Scripting.FileSystemObject")
Dim goWS : Set goWS = CreateObject("WScript.Shell")
Dim tsIn : Set tsIn = goFS.OpenTextFile(csFSpec)
Do Until tsIn.AtEndOfStream
Dim sLine : sLine = tsIn.ReadLine
goWS.Run """C:\Program Files\Internet Explorer\IEXPLORE.EXE"" """ & sLine & """", 1, True
Loop
tsIn.Close
谢谢,它正在工作。但是,当我关闭浏览器时,它抛出以下错误<代码>异常设置“可见”:“调用的对象已与其客户端断开连接。(HRESULT中的异常:0x80010108(RPC_E_disconnected))”第8行字符:11+,而($ie.Visible=$true){+~~~~~~~~~~~~~~~~~~~~~~~~~~+CategoryInfo:NotSpecified:(:)[],SetValueInvocationException+FullyQualifiedErrorId:exception当设置时另外,假设我在一个包含100个URL的文本文件上运行脚本,但我想停止打开该站点,在X个URL之后如何打开该站点?从现在开始,它会一直打开URL,直到EOF。查看编辑后的答案——新的while语句将避免这种情况。还有,我的注释s提到第一个版本会引发异常。如果要停止它,请转到PowerShell窗口并关闭它或按Ctrl+C。明白了!是的,手动关闭它可以完成此任务。再次感谢。完成后请更新它。