title: VBA scraping with javaScript - Troubles to use execScript?
body: <p>I’d need to create a table with the result of the earnings. I was able to manage the first page, but I need to complete the table with all the previous earnings as well.
  I don’t know how to “click” the “Mostrar Mas” button using exeScript, get the result and keep doing it till the table is completed</p>
  <p>This is the code I’ve put together so far.</p>
  <pre><code>Sub fundamentals()
      'Primer pagina de earnings
      Dim XMLReq As New MSXML2.XMLHTTP60
      Dim HTMLDoc As New MSHTML.HTMLDocument
      Dim TRs As MSHTML.IHTMLElementCollection
      
      Dim Table As MSHTML.IHTMLTable
      Dim Rows As MSHTML.IHTMLElementCollection
      Dim TD As MSHTML.IHTMLElement
  
      Dim ws As Worksheet: Set ws = ThisWorkbook.Sheets(&quot;Apple&quot;)
      
      XMLReq.Open &quot;POST&quot;, &quot;https://es.investing.com/equities/apple-computer-inc-earnings&quot;, False
      'XMLReq.Open &quot;POST&quot;, &quot;https://es.investing.com/equities/morehistory&quot;, False
      XMLReq.setRequestHeader &quot;Content-Type&quot;, &quot;application/x-www-form-urlencoded&quot;
      XMLReq.setRequestHeader &quot;Accept&quot;, &quot;text/plain&quot;
      XMLReq.setRequestHeader &quot;X-Requested-With&quot;, &quot;XMLHttpRequest&quot;
      
      XMLReq.send
      
      If XMLReq.Status &lt;&gt; 200 Then
          MsgBox &quot;problem&quot; &amp; vbNewLine &amp; XMLReq.Status &amp; &quot;- &quot; &amp; XMLReq.statusText
          Exit Sub
      End If
      
      
      HTMLDoc.body.innerHTML = XMLReq.responseText
      
      Set Table = HTMLDoc.getElementById(&quot;earningsHistory6408&quot;)
      Set Rows = Table.Rows
      Set TDs = Rows.tags(&quot;TR&quot;)
      
      i = 0: j = 8: k = 3
      For Each TD In TDs
          If i = 0 Then
              Headerarray = Split(TD.innerHTML, &quot;&lt;TH&quot;)
              ws.Cells(2, j) = Split(Split(Headerarray(1), &quot;&gt;&quot;)(1), &quot;&lt;&quot;)(0): j = j + 1                'Fecha de presentacion
              ws.Cells(2, j) = Split(Split(Headerarray(2), &quot;&gt;&quot;)(1), &quot;&lt;&quot;)(0): j = j + 1                'Período terminado
              ws.Cells(2, j) = Split(Split(Headerarray(3), &quot;&gt;&quot;)(1), &quot;&lt;&quot;)(0): j = j + 1                'BPA
              ws.Cells(2, j) = Split(Split(Split(Headerarray(4), &quot;&gt;&quot;)(1), &quot;;&quot;)(2), &quot;&lt;&quot;)(0): j = j + 1 'Previsión
              ws.Cells(2, j) = Split(Split(Headerarray(5), &quot;&gt;&quot;)(1), &quot;&lt;&quot;)(0): j = j + 1                'Ingresos
              ws.Cells(2, j) = Split(Split(Split(Headerarray(6), &quot;&gt;&quot;)(1), &quot;;&quot;)(2), &quot;&lt;&quot;)(0)            'Previsión
          Else
              TDarray = Split(TD.innerHTML, &quot;&lt;TD&quot;)
              ws.Cells(k, j) = Split(Split(TDarray(1), &quot;&gt;&quot;)(1), &quot;&lt;&quot;)(0): j = j + 1 'Fecha de publicacion
              ws.Cells(k, j) = Split(Split(TDarray(2), &quot;&gt;&quot;)(1), &quot;&lt;&quot;)(0): j = j + 1 'Periodo terminado
              ws.Cells(k, j) = Split(Split(TDarray(3), &quot;&gt;&quot;)(1), &quot;&lt;&quot;)(0): j = j + 1 'BPA
              ws.Cells(k, j) = Split(Split(TDarray(4), &quot;;&quot;)(2), &quot;&lt;&quot;)(0): j = j + 1 'Prevision
              ws.Cells(k, j) = Split(Split(TDarray(5), &quot;&gt;&quot;)(1), &quot;&lt;&quot;)(0): j = j + 1 'Ingresos
              ws.Cells(k, j) = Split(Split(TDarray(6), &quot;;&quot;)(2), &quot;&lt;&quot;)(0): j = j + 1 'Prevision
              
          End If
          i = i + 1: j = 8: k = k + 1
      Next
      
  End Sub
  </code></pre>
  <p><a href="https://i.stack.imgur.com/fEhOs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fEhOs.png" alt="enter image description here" /></a></p>
  <p>I’ve tried to click the button with this code, but none of the lines are correct:</p>
  <p>Call XMLReq. responseText.execScript(&quot;showMoreEarningsHistory(6408, this)&quot;) &lt; Invalid qualifier</p>
  <p>Call XMLReq.execScript(&quot;showMoreEarningsHistory(6408, this)&quot;) &lt;- Object does not support this
  property or method</p>
  <p><a href="https://i.stack.imgur.com/WCoLY.png" rel="nofollow noreferrer">Inspect of Mostrar Mas button</a></p>
  <p>If I manually click the button this is what I see in the dev tools:</p>
  <p><a href="https://i.stack.imgur.com/nZy6U.png" rel="nofollow noreferrer">dev tools - Network tab</a></p>
  <p>Then if I run this code I get what I need, but he BIG question is how I can get the information in advance?</p>
  <p><a href="https://i.stack.imgur.com/jvnim.png" rel="nofollow noreferrer">code</a></p>