0

I built some code to retrieve stock data from Yahoo as a CSV file, and it works fine. When I change the URL to the perfectly legal version that recalls minutewise data from Google instead, it fails on the

objHTTP.open "GET", strURL, False

statement.

The following code shows both URLs, although obviously only the final one is called. Both URLs work when posted into the address bar of a browser.

Can anyone explain why the call to Google's page won't Open?

  option explicit

   Dim objHTTP
   dim strURL
   dim objFile

   dim objFSO
   Set objFSO = CreateObject("Scripting.FileSystemObject")
   Set objHTTP = CreateObject("MSXML2.XMLHTTP")
   ' WORKS:
   strURL = "http://real-chart.finance.yahoo.com/table.csv?s=UPRO&a=04&b=21&c=2016&d=04&e=31&f=2016&g=d&ignore=.csv"
   ' DOES NOT WORK:
   strURL = "www.google.com/finance/getprices?q=UPRO&i=60&p=20d&f=d,c,v,k,o,h,l&df=cpct&auto=0&ei=Ef6XUYDfCqSTiAKEMg"

   objHTTP.open "GET", strURL, False
   objHTTP.send
   msgbox objHTTP.responseText 
   Set objFile = objFSO.CreateTextFile _
      ("Yahoo.csv", 2)
   objFile.Write objHTTP.ResponseText
   objFile.Close
user692942
  • 16,398
  • 7
  • 76
  • 175
Joe Marfice
  • 151
  • 2
  • 18

1 Answers1

2

You are missing http:// from the broken URL. When I added this, I got response data.

langstrom
  • 1,652
  • 11
  • 14
  • 2
    Should be the accepted answer, may be try padding out the answer a bit? The reason it works is because the [IXMLHttpRequest object](https://msdn.microsoft.com/en-us/library/ms757849(v=vs.85).aspx) expects a valid URL *(which means including the protocol `http` or `https` for example)*. From the docs - *"The requested URL. This can be either an absolute URL, such as `"http://Myserver/Mypath/Myfile.asp"`, or a relative URL, such as `"../MyPath/MyFile.asp"`."* – user692942 Jun 01 '16 at 08:50