Почему моя программа VBA не получает все имена тегов, которые равны «пути» с веб-сайта? - PullRequest
1 голос
/ 07 мая 2020

Мне интересно, сможет ли кто-нибудь помочь мне с этой проблемой. Я пытаюсь создать программу, которая будет находить определенный значок на веб-странице, а затем щелкать все его вхождения на основе имени тега, который имеет элемент. На веб-странице, на которой я пытаюсь это сделать, есть 4 отдельных вхождения тега, который я ищу, но я получаю только 1 результат. Вот что у меня сейчас:


Option Explicit
Private Sub CommandButton1_Click()

Dim HTMLDoc As HTMLDocument
Dim MyBrowser As InternetExplorer
Dim MyHTML_Element As IHTMLElement
Dim MyURL As String
Dim this As Variant


'On Error GoTo Err_Clear
    MyURL = "https://im.academy/login"
    Set MyBrowser = New InternetExplorer
    MyBrowser.Silent = True
    MyBrowser.navigate MyURL
    MyBrowser.Visible = True
    Do
    Loop Until MyBrowser.readyState = READYSTATE_COMPLETE
    Set HTMLDoc = MyBrowser.document

    'fills in the username
    HTMLDoc.all.userInput.Value = "michdoming" 'Enter your email id here

    'fills in the password
    HTMLDoc.all.passInput.Value = "Tinkerock1!" 'Enter your password here

    Set this = HTMLDoc.getElementsByTagName("input")



    'goes through the HMTL elements that have a tag name of "input")
    For Each MyHTML_Element In this

        'Finds the login button which is a submit type
        If MyHTML_Element.Type = "submit" Then

            'clicks the login button
            MyHTML_Element.Click

            Exit For

        End If

    Next

    'loops until the webpage is loaded
    Do While MyBrowser.Busy
    Loop


    MyBrowser.navigate "https://im.academy/enrollerTree"

    'loops until the webpage is loaded
    Do While MyBrowser.Busy
    Loop

'delays the program for 10 seconds
Application.Wait (Now + TimeValue("0:00:10"))

    Set HTMLDoc = MyBrowser.document

    Set this = HTMLDoc.getElementsByTagName("path")

    MsgBox (CStr(this.Length))

    For Each MyHTML_Element In this

       ' If MyHTML_Element.className = "row-expand-icon" Then

            MyHTML_Element.Click

       ' End If

      '  Exit For

    Next



'Err_Clear:
 '   If Err <> 0 Then
  '  Err.Clear
   ' Resume Next
    'End If
MsgBox ("Done")
End Sub

Код сайта:


<!DOCTYPE HTML PUBLIC "HTML5">
<html>
<head>
<title>IM Academy :: My Referrals</title>
<!-- server ip 172.24.32.102 -->
<!-- corp -->
<meta name="viewport" content="width=device-width">
<link href="/images/favicon.png" rel="short icon" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>
<link href="/htdocs/pure-form.css" rel="stylesheet" type="text/css" />
<script defer src="https://use.fontawesome.com/releases/v5.0.6/js/all.js"></script>
<link href="/htdocs/backOffice2019.css?27" rel="stylesheet" type="text/css" />
<link rel="shortcut icon" href="/images/backoffice2019/favicon.ico" type="image/x-icon">
<link rel="icon" href="/images/backoffice2019/favicon.ico" type="image/x-icon">
<script type="text/javascript">
<!--
function ow (x,y) {
   var opt = 'status=yes,menubar=yes,scrollbars=yes,resizable=yes,' + y;
   window.open(x,'',opt);
}
//-->
</script>

</head>
<body>

<div id="moviePage" class="moviePage">
<div id="movie" class="movie">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
 <td align="right"><a href="javascript:movieClose()"><img src="/images/closeX.png" border="0"></a></td>
</tr>
<tr>
 <td ><center><iframe id="movieFrame" src="" width="640" height="460" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></center>
 </td>
</tr>
</table>
<center><a href="javascript:movieClose()">[ Close ]</a></center>
</div>
</div>
<script type="text/javascript">
<!--

document.getElementById('moviePage').style.display="none";
-->
</script>
<div id="outermost">
 <div id="content">
   <div id="header">
    <div id="headerCenter">
     <div id="headerLogo">
      <div id="headerLogoLogo"><a href="/home"><img src="/images/backoffice2019/footerLogo.png" border="0"></a></div> 
      <div id="headerLogoMenu"><div id="headerLogoMenuLink"><a href="javascript:leftColumn()" ><i class="fas fa-bars"></i></a></div></div>
<svg class="svg-inline--fa fa-bars fa-w-14" aria-hidden="true" data-prefix="fas" data-icon="bars" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" data-fa-i2svg=""><path fill="currentColor" d="M16 132h416c8.837 0 16-7.163 16-16V76c0-8.837-7.163-16-16-16H16C7.163 60 0 67.163 0 76v40c0 8.837 7.163 16 16 16zm0 160h416c8.837 0 16-7.163 16-16v-40c0-8.837-7.163-16-16-16H16c-8.837 0-16 7.163-16 16v40c0 8.837 7.163 16 16 16zm0 160h416c8.837 0 16-7.163 16-16v-40c0-8.837-7.163-16-16-16H16c-8.837 0-16 7.163-16 16v40c0 8.837 7.163 16 16 16z"></path></svg>
      </div>
     <div id="headerGoogleSec">
     <div id="google_translate_element"></div>
      <script>
        function googleTranslateElementInit() {
         new google.translate.TranslateElement({
         pageLanguage: 'en',
         layout: google.translate.TranslateElement.InlineLayout.SIMPLE
         }, 'google_translate_element');
        }
      </script><script src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
     </div><! -- header Google sec -->
      <div id="headerRight">
       <div id="headerRightNav">
        <div id="headerProfilePic"><a href="/avatar"><img src="/images/genericPerson.jpg" border="0"></a></div>
        <div id="headerID">ID #1985996</div>
        <div id="headerSettings"><a href="https://im.academy/profile"><img src="/images/headerSettingsIcon.png"></a></div>
        <div id="headerLogout"><a href="/logout"><img src="/images/headerLogoutIcon.png"></a></div>
       </div><!-- header right Nac -->
      </div>
    </div><!-- header center -->
   </div><!-- header -->
  <div id="bodyRow">
   <div id="bodyCell">
    <div id="mainBody">
     <div id="leftCol">
<br>
      <div class="profile_picture"><a href="/avatar"><img src="/images/genericPerson.jpg" border="0"></a></div>
      <div class="profile_name">Michael Dominguez</div>
      <div class="profile_id">1985996</div>

<br>
       <div class="leftColHeader">Menu</div>
         <ul>
          <li><a href="/home"><span>Home</span></a></li>
          <li><a href="https://www.im.center/" target="_blank"><span>im.center</span></a></li>
          <li><a href="https://apps.apple.com/us/app/im-academy/id1475073258" target="_blank"><span>IM academy app Apple</span></a></li>
          <li><a href="https://play.google.com/store/apps/details?id=com.growthengineering.imarket&hl=en_US" target="_blank"><span>IM academy app Android</span></a></li>

          <li><a href="/legacyLinks"><span>Old Links</span></a></li>
          <li><a href="/myURL"><span>My Referral Links</span></a></li>
          <li><a href="/enrollerTree"><span>My Referrals</span></a></li>
          <li><a href="https://im.academy/upgrade"><span>Shopping Cart</span></a></li>
          <li><a href="/recentOrders"><span>Order History</span></a></li>
          <li><a href="/enrollers"><span>Upline IBOs</span></a></li>
          <li><a href="/BOSpamPolicy"><span>Spam Policy</span></a></li>
          <li><a href="https://im.academy/profile"><span>Personal Info</span></a></li>
          <li><a href="/contactUs"><span>Contact Us</span></a></li>
          <li><a href="/logout"><span>Logout</span></a></li>
         </ul>


     </div>


     <div id="liBody">
            <div id="liBodyContent" style=" height:calc(100% - 134px); ">


<div id="breadCrumbs">
 <a href="/index">Home</a>&nbsp;&nbsp;<span class="bcArrow">&#187;</span>&nbsp;&nbsp;
 <div class="breadCrumbName"> My Referrals</div>
</div>
             <div class="pageTitle">My Referrals</div>
               <br>
            <div class="liBodyContent">


<center><a href="enrollerTreeGraphic"><button type="button" style="font-size:11px">Graphic View</button></a></center>
<!--2020-05-07 -->
<script language="javascript">
<!--
function goButton() {
   document.forms['ETREE'].elements['ID'].value = document.forms['ETREE'].elements['UPLINE'].value;
   document.forms['ETREE'].submit();
}
function go(x) {
   document.forms['ETREE'].elements['ID'].value = x;
   document.forms['ETREE'].submit();
}
-->
</script>

<p>
<table width="100%">
<tr>
<td width="50%" valign="top">

<table class="styledTable  textL">
<tr >
<td colspan="2"><b>Your Stats  (michdoming)</b></td>
</tr>
<tr >
<td>Personally Enrolled IBOs</td>
<td align="right"></td>
</tr>
<tr >
<td>Personally Enrolled Customers</td>
<td align="right">1</td>
</tr>
</table>

</td>
</tr>
</table>
</p>

<p><b>Important:</b> If you have over 5,000 Members in your unilevel tree, it may take longer to open all levels.  To find a specific person in your organization faster, we suggest using the <a href="findUser?SEARCH=2&VALUE=1985996"><u>Find User</u></a> page.</p>


<style>
.styledTable td {
   font-size:12px;
   line-height:1.7em;
}
body {
   padding: 20px;
   box-sizing: border-box;
}
.styledTable{
   overflow: hidden;
   width: 100%;
}
.cellWithComment{
   position:relative;
}
.cellComment{
   display:none;
   position:absolute;
   z-index:100;
   border:1px;
   width:300px;
   background-color:white;
   border-style:solid;
   border-width:1px;
   border-color:#5bb62e;
   padding:10px;
   top:0px;
   left:0px;
   border-radius:4px;
   color:black;
}

.cellWithComment:hover span.cellComment{
   display:block;
}

</style>

<p></p>

 <script type="application/javascript"> var openIframes = []; function getTopLevelWindow() { var myparent = window.parent; while (myparent !== myparent.parent) myparent = myparent.parent; return myparent; } function putOrDeleteIframe(iframeId, frameWindow) { var alreadyInIndex = -1; for (var i = 0; i < openIframes.length; i++) { if (openIframes[i][0] === iframeId) { alreadyInIndex = i; } } if (alreadyInIndex > -1) { openIframes.splice(alreadyInIndex, 1); } else { openIframes.push([iframeId, frameWindow]); } } var topLevelWindow = getTopLevelWindow(); var isTopLevel = topLevelWindow === window; function iframeScript_iFrameTable () { var iframeId = "iFrameTable"; if (isTopLevel) { window.addEventListener("message", function(e) { if (e.data.iframeId) { putOrDeleteIframe(e.data.iframeId, e.source); } }); if (iframeId !== "") { putOrDeleteIframe(iframeId, window); }  var poller = setInterval(function() { console.log(openIframes.length + " frames open"); for (var i = 0; i < openIframes.length; i++) { var iframeId = openIframes[i][0]; var mywindow = openIframes[i][1]; var iFrameEl = mywindow.document.getElementById(iframeId); if (iFrameEl && iFrameEl.contentWindow) { var iFrameWindow = iFrameEl.contentWindow; var iFrameDoc = iFrameWindow.document; var table = iFrameDoc.getElementsByTagName("table")[0]; if (table) { var tableStyle = iFrameWindow.getComputedStyle(table); var marginTop = parseInt(tableStyle["margin-top"].split("px")[0]); var marginBottom = parseInt(tableStyle["margin-bottom"].split("px")[0]); var paddingTop = parseInt(tableStyle["padding-top"].split("px")[0]); var paddingBottom = parseInt(tableStyle["padding-bottom"].split("px")[0]); var height = parseInt(tableStyle["height"].split("px")[0]); var newHeight = height + marginBottom + marginTop + paddingBottom + paddingTop; iFrameEl.height = newHeight; var end = iFrameDoc.getElementById("end_data"); if (end) { clearInterval(poller); } } } } }, 150); } else { topLevelWindow.postMessage({iframeId: iframeId}, topLevelWindow.location.origin); } } if (isTopLevel) { iframeScript_iFrameTable(); } </script>

<td class="row-expand-icon"><svg class="svg-inline--fa fa-plus-circle fa-w-16 green" aria-hidden="true" data-prefix="fa" data-icon="plus-circle" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" data-fa-i2svg=""><path fill="currentColor" d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm144 276c0 6.6-5.4 12-12 12h-92v92c0 6.6-5.4 12-12 12h-56c-6.6 0-12-5.4-12-12v-92h-92c-6.6 0-12-5.4-12-12v-56c0-6.6 5.4-12 12-12h92v-92c0-6.6 5.4-12 12-12h56c6.6 0 12 5.4 12 12v92h92c6.6 0 12 5.4 12 12v56z"></path></svg><!-- <i class="fa fa-plus-circle green" aria-hidden="true"></i> --></td>
 <style> #iFrameTable { width: 100%; border: none; } </style> <iframe id="iFrameTable" src="?ID=1985996&PDATE=2020-05-07&IFRAME_TABLE=1&MONTH=C&MONTH_TEXT=April&TREE_BV=0&TREE_USERS=0&UP_ONE=0&LEVEL=1&RANK=0" ></iframe>
<div class="alertBox">
<div class="alertBoxPadding">
<ul>
<li>IBO Kit: This column will show if that individual's IBO kit has been paid in the last 30 days</li>
<li>PV: This column will show that individual's personal subscription volume and any a la carte add on's in the last 30 days</li>
<li>PSV: This column will show that individual's OVERALL Personal Enrolled Sales Volume in the last 30 days</li>
<li>PRSV: This column will show that individual's OVERALL Personally Enrolled Customer ONLY Volume in the last 30 days</li>
<li>Total GV: This column will show the SUM of that individual's total sales volume in the last 30 days</li>
<li>Total Customer GV: This column will show the SUM of that individual's total customer sales volume in the last 30 days</li>
<li>55/45 GV: This column will show that individual's qualified sales volume over the last 30 days... after the 55% customer ratio rule has been applied</li>
</ul>
</div>
</div>
             </div>
            </div><!-- li body content -->
    <div id="footer">
     <div id="footerContent">
<br>
   <div class="footer-left">
      <div class="footer-logo">
         <a href="/"><img src="/images/backoffice2019/footerLogo.png" alt=iMarketsLive"></a>
      </div>
   </div>
   <div class="footer-main-container">
     <a href="/home"><img src="/images/backoffice2019/masteryAcademyLogo.png"></a><br>
<a href="/privacyPolicy">Privacy Policy</a> | <a href="/policies">Policies and Procedures</a> | <a href="/termsAndConditions">Terms & Conditions</a> | <a href="/refundPolicy">Refund Policy</a> | <a href="/spamPolicy">Spam Policy</a> | <a href="/nfaNotice">NFA Notice</a>
<br>
Copyright &copy; 2020 iMarketsLive.
     </div>
     <div class="footer-right"></div>
     <div style="clear: both;"></div>
   </div>
    <div id="footerDisclaimer">
FULL RISK DISCLOSURE: Trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing financial security or life style. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is no guarantee of future results.
    </div>
     </div><!-- li body -->
     <div style="clear:both"></div>
    </div><!-- main center-->
   </div><!-- body cell -->
  </div><!-- body row -->
 </div><!-- centerContent -->

</body>

<script type="text/javascript">
<!--
var docHeight = jQuery(document).height();
var windowHeight = jQuery(window).height();
function movie(x,y) {
   document.getElementById('moviePage').style.height=docHeight + "px";
   document.getElementById('moviePage').style.display="";
   var link = "www.youtube.com/embed/_3k7WqwVLT0";
   if (x) {
      link = x;
   }
   if (y == 2) {
      document.getElementById('movieFrame').src = "https:" + link;
   } else {
      document.getElementById('movieFrame').src = "https://" + link + "?autoplay=1&rel=0";
   }
   MakeCenter('movie');
}

function leftColumn() {
  jQuery('#leftCol').slideToggle(400)
}



function movieClose() {

   document.getElementById('moviePage').style.display="none";
   document.getElementById('movieFrame').src ='';
}

function MakeCenter(elementId)  {

     var scrollHeight = jQuery(document).scrollTop();

     var objControl=document.getElementById(elementId);


     if(objControl !=null)  {

          var left=(objControl.offsetParent.clientWidth/2)-(objControl.clientWidth/2)+objControl.offsetParent.scrollLeft;

          var top=(windowHeight/2)-(objControl.clientHeight/2)+scrollHeight;

              document.getElementById('moviePage').style.top=scrollHeight + "px"; 
              top=(objControl.clientHeight/2);

           objControl.style.top= top + "px";
           objControl.style.left= left + "px";
           var _scrollHeight = jQuery(document).scrollTop();
          }
    }

</html>

...