制作一个从当前网页中提取信息的脚本

时间:2016-12-11 23:25:59

标签: vbscript macros automation webpage bots

所以我正在尝试创建一个脚本或宏,当我按下键盘上的按钮或宏时,从我当前加载的网页中提取信息。我正在查看vbs,但我看到你必须打开一个新的IE实例或其他网络浏览器。

1 个答案:

答案 0 :(得分:0)

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

<VirtualHost *:80>
  ServerAdmin webmaster@localhost
  DocumentRoot /var/www/webroot
  <Directory /var/www>
    Options FollowSymLinks
    AllowOverride All
 </Directory>

 <Location "/">
    # Default to Basic Auth protection for any stie
    AuthType Basic
    AuthName "Keawe Development"
    AuthUserFile /host/.htpasswd
    Require valid-user

    # If the request goes to a rest page: bypass basic auth
    SetEnvIf Request_URI ^/rest/ noauth=1
    Allow from env=REDIRECT_noauth
    Allow from env=noauth

    Order Deny,Allow
    Satisfy any
    Deny from all
  </Location>

  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

要像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

这会在所选文本右键菜单中添加一个菜单项,以导航到所选文本(不是链接,而是有效的URL)。

msgbox ie.document.body.innertext

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

<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>

这是来自 Internet Explorer 5 Power Toys ©Microsoft。它在新窗口中列出链接。它是JScript但VBScript以相同的方式使用相同的对象。 http://threeclicks.com/powertoysie5.htm

Windows Registry Editor Version 5.00

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

同样可以打开和关闭编辑页面的功能。

点击工具菜单。

<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>

ViewPage.html

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"

EditPage.html

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