-3
因此,我正在嘗試創建一個腳本或宏,用於在我按下鍵盤上的按鈕或宏時從當前已加載的網頁中獲取信息。我在看vbs,但在我看來,無論在哪裏,你都必須打開IE或其他網絡瀏覽器的新實例。製作一個腳本,從當前網頁中提取信息
因此,我正在嘗試創建一個腳本或宏,用於在我按下鍵盤上的按鈕或宏時從當前已加載的網頁中獲取信息。我在看vbs,但在我看來,無論在哪裏,你都必須打開IE或其他網絡瀏覽器的新實例。製作一個腳本,從當前網頁中提取信息
這列出了所有的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 (" 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>
歡迎作爲一個新的用戶SO。請參考[Tour](http://stackoverflow.com/tour)並閱讀[Help-Center/ask](http://stackoverflow.com/help/on-topic)。 SO不是一個腳本寫作服務。 爲了獲得幫助,您應該做得比您期望的更多,首先展示您在代碼中所付出的努力。 – LotPings
發佈你到目前爲止...我有一個可行的HTML抓取腳本,但需要看你的努力 –