从iFrame中的网站检索文本

时间:2018-11-02 13:20:29

标签: html vba

我正在尝试从iframe中加载的网站元素中检索文本。

我已经在vb中启动了一些代码以打开并导航到相应的页面。我从来没有在教室里学习编程,所以我想我缺少一些关键要素来完成这项工作。我在下面添加了我的代码,如果不好的话(抱歉,没有编程培训),我们感到抱歉。 这里的目标是进入网站,从员工考勤卡中获取数据,并将其放入excel中,以便我进行操作。

我一直在寻找来自各地的答案,但并不高兴。 我已经尝试了很多行,但是没有任何效果。

请帮助。

这是我得到的最接近的,但是在尝试获取属性innertext时,最后两行仍然出现自动化错误。

Sub openkronos()

Dim usercode As String
Dim userpass As String

usercode = Cells(1, 2).Value
userpass = Cells(2, 2).Value

Set ie = CreateObject("InternetExplorer.Application")

ChromeLocation = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
MyURL = "https://tollgroup.kronos.net/wfc/applications/navigator/Navigator.do"
Shell (ChromeLocation & " -url " & MyURL)

Do While ie.Busy Or ie.ReadyState <> READYSTATE_COMPLETE
    DoEvents
Loop

Application.Wait Now + TimeValue("00:00:04")

SendKeys usercode
SendKeys "{TAB}"
SendKeys userpass
SendKeys "{ENTER}", True

x = 960
y = 238

Application.Wait Now + TimeValue("00:00:04")

SetCursorPos x, y

mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0

Application.Wait Now + TimeValue("00:00:02")

x = 459
y = 246

SetCursorPos x, y

mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0

Application.Wait Now + TimeValue("00:00:10")

x = 1684
y = 503

SetCursorPos x, y

mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0

Application.Wait Now + TimeValue("00:00:04")


test = ie.document.getElementById("iFrame_*").getElementById("iframe_iFrame_*").contentWindow.document.getElementById("column-Date-Row-0").getattribute("InnerText")
MsgBox test


End Sub

这是HTML

<body scroll="no" onresize="checkAndRefreshIFrame()" onload="onAppInitialized();showPasswordExpirationPopUp();" onunload="clearOcnSessionTsFlag();">

<!-- saved from url=(0014)about:internet -->










<meta http-equiv="Content-Type" content="text/html; charset=utf-8">



<div id="modalWindow" class="jqx-window-modal jqx-window-modal-bluefin" style="opacity: 0.3; display: none; position: absolute; top: 0px; left: 0px; width: 100%; height: 100%; z-index: 18000"></div>
<div id="passwordExpirationNavErrorPopUp" style="display:none">
<div class="popup-message jqx-rc-all jqx-rc-all-bluefin jqx-window jqx-window-bluefin jqx-popup jqx-popup-bluefin jqx-widget jqx-widget-bluefin jqx-widget-content jqx-widget-content-bluefin ng-scope" role="dialog" tabindex="0" hidefocus="true" style="outline: medium none; width: 420px; height: 139px; min-height: 30px; max-height: 600px; min-width: 100px; top: 73.5px; left: 456px; z-index: 18001;top:200px">
    <div class="jqx-window-header jqx-window-header-bluefin jqx-widget-header jqx-widget-header-bluefin jqx-disableselect jqx-disableselect-bluefin jqx-rc-t jqx-rc-t-bluefin alert-error" style="position: relative; width: 380px;"><div style="float: left; direction: ltr; margin-top: 6px;"><span ng-bind-template="WARNING" class="ng-binding">ERROR</span></div><div id="closeButton" onclick="dismissPopUp();" class="jqx-window-close-button-background jqx-window-close-button-background-bluefin" style="visibility: visible; width: 21px; height: 16px; margin-right: 20px; margin-left: 0px; position: absolute; right: 0px;"><div class="jqx-window-close-button jqx-window-close-button-bluefin jqx-icon-close jqx-icon-close-bluefin" style="width: 100%; height: 100%;"></div></div><div class="jqx-window-collapse-button-background jqx-window-collapse-button-background-bluefin" style="visibility: hidden; width: 16px; height: 16px; margin-right: 20px; margin-left: 0px; position: absolute; right: 23px;"><div class="jqx-window-collapse-button jqx-window-collapse-button-bluefin jqx-icon-arrow-up jqx-icon-arrow-up-bluefin" style="width: 100%; height: 100%; top: 0px;"></div></div></div>
    <div class="container-fluid action-wrapper jqx-window-content jqx-window-content-bluefin jqx-widget-content jqx-widget-content-bluefin jqx-rc-b jqx-rc-b-bluefin" style="width: 420px; height: 97px;">
            <hr>
            <div class="action-body row-fluid">
                <div class="span12 alert-message">
                    <i class="icon-stack">
                        <i class="icon-k-circle" style="font-size:21px"></i>
                        <i class="icon-k-cancel-circle error" style="font-size:21px"></i>
                    </i>
                    <span id="days" ng-bind-template="Default Popup message." class="ng-binding" style="padding-left:15px">
                    Failed to retrieve data from the server</span>
                </div>
            </div>
            <footer class="row-fluid">
                <div class="span12">
                    <button class="btn" id="message-btn" onclick="dismissPopUp();">Ok</button>
                </div>
            </footer>
    </div>
</div>
</div>
<div id="passwordExpirationNavPopUp" style="display:none">
<div id="messageFrameworkPopUp" class="popup-message jqx-rc-all jqx-rc-all-bluefin jqx-window jqx-window-bluefin jqx-popup jqx-popup-bluefin jqx-widget jqx-widget-bluefin jqx-widget-content jqx-widget-content-bluefin ng-scope" role="dialog" tabindex="0" hidefocus="true" style="outline: medium none; width: 420px; height: 139px; min-height: 30px; max-height: 600px; min-width: 100px; top: 73.5px; left: 456px; z-index: 18001;top:200px">
    <div class="jqx-window-header jqx-window-header-bluefin jqx-widget-header jqx-widget-header-bluefin jqx-disableselect jqx-disableselect-bluefin jqx-rc-t jqx-rc-t-bluefin alert-warning" style="position: relative; width: 380px;"><div style="float: left; direction: ltr; margin-top: 6px;"><span ng-bind-template="WARNING" class="ng-binding">WARNING</span></div><div id="closeButton" onclick="hideNavPopup();" class="jqx-window-close-button-background jqx-window-close-button-background-bluefin" style="visibility: visible; width: 21px; height: 16px; margin-right: 20px; margin-left: 0px; position: absolute; right: 0px;"><div class="jqx-window-close-button jqx-window-close-button-bluefin jqx-icon-close jqx-icon-close-bluefin" style="width: 100%; height: 100%;"></div></div><div class="jqx-window-collapse-button-background jqx-window-collapse-button-background-bluefin" style="visibility: hidden; width: 16px; height: 16px; margin-right: 20px; margin-left: 0px; position: absolute; right: 23px;"><div class="jqx-window-collapse-button jqx-window-collapse-button-bluefin jqx-icon-arrow-up jqx-icon-arrow-up-bluefin" style="width: 100%; height: 100%; top: 0px;"></div></div></div>
    <div class="container-fluid action-wrapper jqx-window-content jqx-window-content-bluefin jqx-widget-content jqx-widget-content-bluefin jqx-rc-b jqx-rc-b-bluefin" id="popupMessageContainer" style="width: 420px; height: 97px;">
            <hr>
            <div class="action-body row-fluid" id="warningNavMessage">
                <div class="span12 alert-message">
                    <i class="icon-stack">
                        <i class="icon-k-triangle" style="font-size:21px"></i>
                        <i class="icon-k-warning warning" style="font-size:21px"></i>
                    </i>
                    <span id="days" ng-bind-template="Default Popup message." class="ng-binding" style="padding-left:15px">null
</span>
                </div>
            </div>
            <footer class="row-fluid">
                <div class="span12">
                    <button class="btn" id="message-btn" onclick="hideNavPopup();">Ignore</button>
                    <button class="btn" id="message-btn" onclick="changeNavPasswordLink();">Change Password</button>
                </div>
            </footer>
    </div>
</div>
</div>




<script language="JavaScript" type="text/javascript">
function onAppInitialized(){
   // Force the browser to set flex app with focus
   if (document.getElementById('Navigator') != null) {
        document.getElementById('Navigator').focus();
        // Set the client-side flag indicating the navigator window is visible (for one-click navigation feature)
        localStorage.setItem("ocn-session-ts", getDateTimeStamp());
   }
}

function checkAndRefreshIFrame(){
    if (document.getElementById('Navigator') != null) {
    var height = 0;
           if (window.innerHeight){
                height = window.innerHeight;
              }
           else {
              height = document.documentElement.clientHeight;
           }

           var nav = document.getElementById('Navigator');
       nav.height = height;
        // navigator_refreshIFrame is defined in kronos_navigator.js
        if (typeof window.navigator_refreshIFrame === 'function') {
           window.navigator_refreshIFrame();
            // Reset the client-side flag indicating the navigator window is visible (for one-click navigation feature)
            localStorage.setItem("ocn-session-ts", getDateTimeStamp());
        }
    }
}

// This method is used by the one-click navigation feature to determine if this window is still open.
function clearOcnSessionTsFlag(){
   // Set the value to zero on the unload event to flag the fact that this window was closed
   localStorage.setItem("ocn-session-ts", 0);
   return true;
}

// Return a date stamp in milliseconds.
function getDateTimeStamp(){
   var dateStamp = new Date();
   return dateStamp.getTime();
}

//Handle browser validation
function handleBrowserValidation(){
    var browserVersionWarning = "null";
    if(browserVersionWarning == 'com.kronos.wfc.ngui.navigator.browser.unsupported.warning'){
            browserVersionWarning = "Unsupported browser.";
    }
    else if(browserVersionWarning == 'com.kronos.wfc.ngui.navigator.browser.unsupported.msie.warning'){
        browserVersionWarning = "Unsupported browser. Users of IE 8 and higher should turn off Compatibility View.";
    }
    var flashContentHeight = "100%"; 
    var backgroundColor = "#000000";
    if(browserVersionWarning != 'null'){
        var browserWarningContent = '<body style="background-color:' + backgroundColor + '">' 
            + '<div id="browserWarning" style="#position:relative; height:auto; overflow:hidden; font-family:Seqoe UI,sans-serif; text-align:center; color:#FFFFFF; font-size:85%;">'
            + browserVersionWarning 
            + '</div></body>';          
        document.write(browserWarningContent);
        flashContentHeight = "97%";
    }
    return flashContentHeight;
}



if (false == true || true == true) {
<!--

// Version check for the Flash Player that has the ability to start Player Product Install (6.0r65)
var hasProductInstall = DetectFlashVer(6, 0, 65);
// Version check based upon the values defined in globals
var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
var height = 0;
if (window.innerHeight){
     height = window.innerHeight;
   }
else {
   height = document.documentElement.clientHeight;
}

height = height + "px";
if ( hasProductInstall && !hasRequestedVersion ) {
    // DO NOT MODIFY THE FOLLOWING FOUR LINES
    // Location visited after installation is complete if installation is required
    var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
    var MMredirectURL = window.location;
    document.title = document.title.slice(0, 47) + " - Flash Player Installation";
    var MMdoctitle = document.title;
    var flashContentHeight = handleBrowserValidation();

    AC_FL_RunContent(
        "src", "/wfcstatic/applications/navigator/playerProductInstall",
        "FlashVars", "MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+"",
        "width", "100%",
        "height", height,
        "align", "middle",
        "id", "Navigator",
        "quality", "high",
        "bgcolor", "#ffffff",
        "name", "Navigator",
        "allowScriptAccess","sameDomain",
        "type", "application/x-shockwave-flash",
        "pluginspage", "http://www.adobe.com/go/getflashplayer",
        "wmode", "opaque"
    );
    showHiddenDiv();
    if (true == false) {
        jQuery("#container").css('display', 'none');

        // Force the browser to set flex app with focus
        jQuery("#Navigator").focus();
    }
} else if (hasRequestedVersion) {
    if (true == true && true == true) {
        // ask the server to prepare the application context and ui model
        var url = "/wfc/bridge/datapreparation/rest/1.0/prepareData";
        makeAjaxCall(url);
    }
    var flashContentHeight = handleBrowserValidation();
    // if we've detected an acceptable version
    // embed the Flash Content SWF when all tests are passed
    AC_FL_RunContent(
            "src", "/wfcstatic/applications/navigator/Navigator?version=8.1.1.569",
            "flashVars", "loadingApplication=Loading the application...&loadingLibraries=Loading the libraries...&loadingApplicationData=Loading the application data...&loadingWidget=Loading the&loadingWidget_single=widget...&loadingWidget_multiple=widgets...&SWFObjectId=Navigator&navigatorContext=&swfVersion=8.1.1.569&isSSO=true",
            "width", "100%",
            "height", height,
            "align", "middle",
            "id", "Navigator",
            "quality", "high",
            "bgcolor", "#ffffff",
            "name", "Navigator",
            "allowScriptAccess","sameDomain",
            "type", "application/x-shockwave-flash",
            "pluginspage", "http://www.adobe.com/go/getflashplayer",
            "wmode", "opaque"
    );
    if (true == true) {
        showHiddenDiv();
    }
  } else {  // flash is too old or we can't detect the plugin
      var alternateContent = '<body style="background-color:#234781">'
            +'<div style="#position: relative; #top: 40%; font-family:Seqoe UI,sans-serif; text-align:center; color: #333333; font-size: 18px; ">'
            +'<p>This application requires the Adobe Flash Player.</p>'
            +'<p><a href=http://www.adobe.com/go/getflash/><img src="/wfcstatic/applications/navigator/assets/get_adobe_flash_player.png"></a></p>'
            + '<p><a href=http://www.adobe.com/go/getflash/>Get Flash</a></p>'
            +'</div></body>';
    if (true == false) {
        jQuery("#container").css('display', 'none');
    }
    document.write(alternateContent);  // insert non-flash content
  }
// -->
}
</script><div id="preloadedDiv" style="visibility: visible;"><embed src="/wfcstatic/applications/navigator/Navigator.swf?version=8.1.1.569" flashvars="loadingApplication=Loading the application...&amp;loadingLibraries=Loading the libraries...&amp;loadingApplicationData=Loading the application data...&amp;loadingWidget=Loading the&amp;loadingWidget_single=widget...&amp;loadingWidget_multiple=widgets...&amp;SWFObjectId=Navigator&amp;navigatorContext=&amp;swfVersion=8.1.1.569&amp;isSSO=true" width="100%" height="597" align="middle" id="Navigator" quality="high" bgcolor="#ffffff" name="Navigator" allowscriptaccess="sameDomain" pluginspage="http://www.adobe.com/go/getflashplayer" wmode="opaque" type="application/x-shockwave-flash"> </div>
<noscript>
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
            id="Navigator" width="100%" height="100%"
            codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
            <param name="movie" value="/wfcstatic/applications/navigator/Navigator.swf?version=8.1.1.569" />
            <param name="quality" value="high" />
            <param name="bgcolor" value="#ffffff" />
            <param name="allowScriptAccess" value="sameDomain" />
             <param name='flashVars' value='loadingApplication=Loading the application...&loadingLibraries=Loading the libraries...&loadingApplicationData=Loading the application data...&loadingWidget=Loading the&loadingWidget_single=widget...&loadingWidget_multiple=widgets...&SWFObjectIdNavigator&swfVersion=8.1.1.569'/>
            <embed src="/wfcstatic/applications/navigator/Navigator.swf?version=8.1.1.569" quality="high" bgcolor="#ffffff"
                width="100%" height="100%" name="Navigator" align="middle"
                play="true"
                loop="false"
                quality="high"
                allowScriptAccess="sameDomain"
                type="application/x-shockwave-flash"
                pluginspage="http://www.adobe.com/go/getflashplayer"
                flashVars="loadingApplication=Loading the application...&loadingLibraries=Loading the libraries...&loadingApplicationData=Loading the application data...&loadingWidget=Loading the&loadingWidget_single=widget...&loadingWidget_multiple=widgets...&SWFObjectId=Navigator&swfVersion=8.1.1.569"
                >
            </embed>
    </object>
</noscript>




<div id="iFrame_287270" style="position: absolute; background-color: rgb(255, 255, 255); border: 0px; visibility: hidden; left: 29px; top: 130px;"><form name="form_iframe_iFrame_287270" method="post" id="form_iframe_iFrame_287270" target="iframe_iFrame_287270" style="display: none;"><input type="hidden" name="eouCurrentPage" value="/wfcstatic/applications/navigator/html5/dist/genies/index.html?version=8.1.1.569&amp;instanceId=c0411920-b745-4eac-b1d1-107563c137dc&amp;personIdList=&amp;modelToken=c0411920-b745-4eac-b1d1-107563c137dc&amp;userLocale=en_US&amp;serverPath=/wfc&amp;isHTMLWidget=true&amp;isMinimized=false&amp;domain=&amp;ssid=iFrame_287270"><input type="hidden" name="isDocDomain" value="false"></form> <iframe locale="en_US" instance="/wfc" token="c0411920-b745-4eac-b1d1-107563c137dc" name="iframe_iFrame_287270" id="iframe_iFrame_287270" src="/wfcstatic/applications/navigator/html5/dist/genies/index.html?version=8.1.1.569&amp;instanceId=c0411920-b745-4eac-b1d1-107563c137dc&amp;personIdList=&amp;modelToken=c0411920-b745-4eac-b1d1-107563c137dc&amp;userLocale=en_US&amp;serverPath=/wfc&amp;isHTMLWidget=true&amp;isMinimized=false&amp;domain=&amp;ssid=iFrame_287270" onload="Navigator.iFrame_287270_load()" frameborder="0" width="1008" height="453" style="position: absolute; left: -10000px; top: -10000px;"></iframe></div><div id="iFrame_236981" style="position: absolute; background-color: rgb(255, 255, 255); border: 0px; visibility: visible; left: 29px; top: 130px;"><form name="form_iframe_iFrame_236981" method="post" id="form_iframe_iFrame_236981" target="iframe_iFrame_236981" style="display: none;"><input type="hidden" name="eouCurrentPage" value="/wfcstatic/applications/navigator/html5/dist/emptimecard/index.html?version=8.1.1.569&amp;instanceId=cf04ed07-66b9-476e-a871-e3fda3c38aa1&amp;personIdList=&amp;modelToken=cf04ed07-66b9-476e-a871-e3fda3c38aa1&amp;userLocale=en_US&amp;serverPath=/wfc&amp;isHTMLWidget=true&amp;isMinimized=false&amp;domain=&amp;ssid=iFrame_236981"><input type="hidden" name="isDocDomain" value="false"></form> <iframe locale="en_US" instance="/wfc" token="cf04ed07-66b9-476e-a871-e3fda3c38aa1" name="iframe_iFrame_236981" id="iframe_iFrame_236981" src="/wfcstatic/applications/navigator/html5/dist/emptimecard/index.html?version=8.1.1.569&amp;instanceId=cf04ed07-66b9-476e-a871-e3fda3c38aa1&amp;personIdList=&amp;modelToken=cf04ed07-66b9-476e-a871-e3fda3c38aa1&amp;userLocale=en_US&amp;serverPath=/wfc&amp;isHTMLWidget=true&amp;isMinimized=false&amp;domain=&amp;ssid=iFrame_236981" onload="Navigator.iFrame_236981_load()" frameborder="0" width="1026" height="440" style="position: absolute;"></iframe></div></body>

0 个答案:

没有答案