locked
How to use XMLHTTP60 instead of ie? RRS feed

  • Question

  • Hi,

    I need to switch from ie to xmhttp60 as it takes ages to load the page. Is there any way to do it? Below the code

    I'm using. Additionally, how can I get the result of this line: "ie.document.parentWindow.execScript ("showMoreEarningsHistory(6435, this)")"

    Sub MostrarMasButton() Dim ie As InternetExplorer Dim CurrentWindow As HTMLWindowProxy url = "https://es.investing.com/equities/amazon-com-inc-earnings" Set ie = New InternetExplorer ie.Visible = True ie.navigate url Do While ie.Busy = True Or ie.readyState <> 4: DoEvents: Loop

    ie.document.parentWindow.execScript ("showMoreEarningsHistory(6435, this)") End Sub


    Tuesday, October 13, 2020 12:30 PM

All replies

  • IE is discontinued.  VBA doesn't directly support other browsers.  You'll need to use use a 3rd party addin.  Almost all browsers can be controlled with a Selenium webdriver.  Someone did a VBA .NET COM DLL called SeleniumBasic that uses Selenium to control the web browser.  This release is dated.  You need to have a webdriver compatible with browser version.  If you update the Chrome and Edge Chromium drivers it seems to work fine.  SeleniumBasic installs at:

    C:\Users\<user>\AppData\Local\SeleniumBasic

    Get correct Chrome webdriver and replace it.  It has to have same name.

    Get correct Edge webdriver and replace it.  You'll need to rename it.

    Firefox doesn't work.

    ' Add Reference to Selenium Type Library '
    
    Private Sub Use_Chrome()
      Dim driver As New ChromeDriver
      driver.Get "https://www.google.co.uk"
      driver.Quit
    End Sub
    
    
    Private Sub Use_Edge()
      Dim driver As New EdgeDriver
      driver.Get "https://www.google.co.uk"
      driver.Quit
    End Sub

    Tuesday, October 13, 2020 1:00 PM
  • I have no experience with Selenium and I'm almost finishing the code for my client. Start from scratch will take time that I don't have unfortunately.

    Any idea if it's possible to use execScrip with xmhttp60 and get the result?


    Tuesday, October 13, 2020 1:29 PM
  • XMLHTTP60 sends 'user agent' as IE7 to perform this operation.  I imagine all websites don't allow IE7.  You might be able to fake out user agent  and make it a supported browser.  Bing or Google XMLHttp.setRequestHeader "User-Agent".  It may be something like this:

    req.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36"

    Even if it works it is short lived.  MS is discontinuing IE next year.

    Selenium is not hard to learn.  There are tons of Youtube videos.  You can use C#, Python and other languages.  Look at XPath to extract elements.  It is VERY powerful.
    Tuesday, October 13, 2020 10:19 PM
  • Even if you get the HTML source using XMLHTTP60, I do not think you will be able to simulate the script because it requires a browser engine.

    Maybe it is possible to acquire the data in a more sanctioned manner, via some API, RSS feeds, etc.

    Since you are familiar with VBA, maybe you can also consider the WebView and WebView2 control, which is based on new Edge browser and can be used in Forms or WPF applications in Visual Basic.

    Wednesday, October 14, 2020 9:20 AM