0

I'm trying to find a way around using IE in my VBA code to access my portfolios in finance.yahoo.com but I'm getting the same message using a soap/rest? format as I do when I open an IE window: "Some parts of this page is not supported on your current browser version. Please upgrade the browser to the latest." It looks like my new calls are being processed by IE also. Is that true? Is there a way around this?

I tried using Selenium to open Firefox but it isn't working with the current version of Firefox (67)

here's the code I'm using now:

Dim xmlhttp  As new MSMXML2.XMLHTTP60    
Dim WebPgDoc As New HTMLDocument    
Dim objNode  As object

With xmlhttp
    .Open "GET", "https://finance.yahoo.com/portfolio/pf_14/view/view_18", False 
    .send
    WebPgDoc.body.innerHTML = .responseText
End With

Set objNode = WebPgDoc.getElementsByTagName("div")

When I look at objNode(70).innertext it has the same error message and missing stock details as when I use code to open IE to open the portfolio .
Any ideas would be greatly appreciated. Thanks

Mathieu Guindon
  • 69,817
  • 8
  • 107
  • 235
Phil
  • 61
  • 1
  • 6
  • 1
    Given the age of the MSXML library, it wouldn't really be surprising? Look into [selenium](https://codereview.stackexchange.com/questions/tagged/selenium+vba) <~ these are all examples of working VBA code using Selenium. – Mathieu Guindon Jun 10 '19 at 19:30
  • Removed references to [tag:excel], since this has nothing to do with Excel. VBA isn't Excel, Excel isn't VBA. – Mathieu Guindon Jun 10 '19 at 19:31
  • Does it work if you [set user-agent](https://stackoverflow.com/a/32922460/11683)? – GSerg Jun 10 '19 at 19:59
  • Just a couple of things: 1) yes, the `IXMLHttpRequest` interface shipped with VBA uses the HTTP engine from Internet Explorer, so it is highly probable that you would get the same error. 2) Such an error message makes me think that an interactive component (e.g. JavaScript) is supposed to build the webpage before you can see the results. In this case, you're not using Yahoo!'s API but you're just trying to robotically scraping what you see on screen. Yahoo offers several free API, you should attack those instead. – Matteo NNZ Jun 10 '19 at 20:09
  • P.s. note that using `XmlHttpRequest` on an API's url is completely browser-independent, as you're requesting data to a dedicated end-point and those are returned directly in JSON (or XML for very old APIs). On the other hand, here you're requesting data to a webpage URL and so you will get the HTML in response, and this HTML may not have been built completely by JavaScript if the `XMLHTTP` server (Internet Explorer for VBA's version) does not support that. – Matteo NNZ Jun 10 '19 at 20:13
  • Thanks for all the replies! Mathieu, I tried Selenium but couldn't get it to work with the latest version of Firefox. I'll check out the samples in the link you have and see if that helps. – Phil Jun 10 '19 at 20:34
  • GSerg, it seems to be giving me a different response with user.agent; I'm trying to figure out if it's right or just different! I'm not too good at this so It'll take me some time to fumble through it. – Phil Jun 10 '19 at 20:43
  • Thanks Matteo. Yes I am scraping. Last time I looked (some time ago) the Yahoo API wasn't very good and didn't have what I needed. May be worth another look if nothing else works. I'm not sure I understand all you wrote yet, but I do think there is Java building part of the page. – Phil Jun 10 '19 at 20:47
  • It's not [Java](https://en.wikipedia.org/wiki/Java), it's [JavaScript](https://en.wikipedia.org/wiki/JavaScript). And practically every webpage in the world relies on it to build what you see on your screen :) – Matteo NNZ Jun 10 '19 at 21:06
  • After a lot of trial and error I was able to open an Opera window but still have errors. While searching around the web I stumbled on AlphVantage and have been experimenting with that. It works pretty well and seems to have all I need right now. Maybe I can get away from both IE and Finance.Yahoo.com in one fell swoop! Thanks for the help everyone. Phil – Phil Jun 12 '19 at 18:14

0 Answers0