2016-12-11 63 views
-3

因此,我正在尝试创建一个脚本或宏,用于在我按下键盘上的按钮或宏时从当前已加载的网页中获取信息。我在看vbs,但在我看来,无论在哪里,你都必须打开IE或其他网络浏览器的新实例。制作一个脚本,从当前网页中提取信息

+3

欢迎作为一个新的用户SO。请参考[Tour](http://stackoverflow.com/tour)并阅读[Help-Center/ask](http://stackoverflow.com/help/on-topic)。 SO不是一个脚本写作服务。 为了获得帮助,您应该做得比您期望的更多,首先展示您在代码中所付出的努力。 – LotPings

+2

发布你到目前为止...我有一个可行的HTML抓取脚本,但需要看你的努力 –

回答

0

这列出了所有的shell窗口。这是资源管理器和Internet Explorer。它包含IE的窗口对象。

Set objShell = CreateObject("Shell.Application") 
Set AllWindows = objShell.Windows 
For Each window in AllWindows 
    msgbox window.locationname 
    msgbox window.parent 
    If window.locationname="Scripts" then window.quit 
Next 

要访问浏览器,如CreateObject使用window.parent

Set ie = CreateObject("InternetExplorer.Application") 

使用

Set ie = window.parent 

要获得所有文字

msgbox ie.document.body.innertext 

这增加了一个菜单项,选择文本右键菜单导航到选定的文本(即不是链接但是是一个有效的URL)。

<HTML> 
<SCRIPT LANGUAGE="vbscript"> 
set parentwin = external.menuArguments 
Set doc = parentwin.document 
Set sel = doc.selection 
set rng = sel.createRange() 
str = lcase(trim(rng.text)) 

If str="" then 
    alert("You must select some text to search for first.") 

ElseIf Left(str,7) = "http://" or Left(str,8) = "https://" then 
    op = str 
Else 
    op = "http://" & str 
End If 

If op <> "" Then open(op) 

</SCRIPT> 
</HTML> 

要添加到菜单,使用此reg文件。

Windows Registry Editor Version 5.00 

[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\&Navigate] 
@="C:\\Windows\\WEB\\selnavigate.htm" 
"contexts"=hex:10 

这是Internet Explorer 5中的电动玩具 ©微软。它在新窗口中列出链接。它的JScript,但VBScript以相同的方式使用相同的对象。 http://threeclicks.com/powertoysie5.htm

<script language=javascript defer> 
var str = new String ("toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes, resizable=yes, top=0, left=0, width=400, height="); 

str = str + (screen.height - 100); 

//alert (screen.height); 

var dlProgress = window.open ("", "linkdownloader", str); 

dlProgress.document.open(); 
dlProgress.document.writeln ("<html>"); 
dlProgress.document.writeln ("<head>"); 
dlProgress.document.writeln ("<title>Links list</title>"); 
dlProgress.document.writeln ("</head>"); 
dlProgress.document.writeln ("<body topmargin=0 leftmargin=0 rightmargin=0 bottommargin=0>"); 
dlProgress.document.writeln ("<font style=\"font: 8pt Verdana, Arial, Helvetica, Sans-serif; line-height:18pt;\">"); 
dlProgress.document.writeln ("<script language=javascript>function navigateClose(str){if (document.my_parent != null){document.my_parent.location.href=str;window.close();}else{alert(\"Please wait until the list has populated.\");}}<\/script>"); 

dlProgress.document.writeln ("&nbsp;List of all links in <b>" + external.menuArguments.document.title + "</b>:<ol>"); 
var links = external.menuArguments.document.links; 
for (i = 0; i < links.length; i++) 
{ 
    if (links(i).innerText != "" && links(i).innerText != " ") 
    { 
     dlProgress.document.writeln ("<li><A HREF='javascript:navigateClose(\"" + links(i).href + "\")' TITLE=" + links(i).href + ">" + links(i).innerText + "</a><BR>"); 
    } 
    else 
    { 
     dlProgress.document.writeln ("<li><A HREF='javascript:navigateClose(\"" + links(i).href + "\")'>" + links(i).href + "</a><BR>"); 
    } 
} 
dlProgress.document.writeln ("</ol><center><a href='javascript:window.close()' style=\"color:#FF0000;text-decoration:none\">close</a></center><BR></body>"); 
dlProgress.document.writeln ("</font></html>"); 
dlProgress.document.close(); 

dlProgress.document.my_parent = external.menuArguments; 
</script> 

如此,这打开和关闭编辑页面的能力。

放在工具菜单上。

Windows Registry Editor Version 5.00 


[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Extensions\{B163952C-2892-4934-AA07-5DEC952BBE3E}] 
"CLSID"="{1FBA04EE-3024-11d2-8F1F-0000F87ABD16}" 
"Script"="C:\\Windows\\Web\\ViewPage.html" 
"MenuText"="Editable Page Off" 
"MenuStatusBar"="Turns off page edit mode" 

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Extensions\{B749639D-8B7C-4741-87A9-7ABD311F6D72}] 
"CLSID"="{1FBA04EE-3024-11d2-8F1F-0000F87ABD16}" 
"Script"="C:\\Windows\\Web\\EditPage.html" 
"MenuText"="Editable Page On" 
"MenuStatusBar"="Turns on page edit mode using standard key and mouse actions" 

ViewPage.html

<script language="VBScript"> 
external.menuArguments.document.body.contenteditable="False" 
</script> 

EditPage.html

<script language="VBScript"> 
external.menuArguments.document.body.contenteditable="True" 
</script>