I am trying to write a macro that will open Edge, go to yahoo finance, get a few pieces of information about a couple of stocks but I get a 429 error. Here is the macro I wrote. What did I do wrong?
Sub GetStockInfo()
' Define variables
Dim Edge As Object
Dim URL As String
Dim StockList As Variant
Dim i As Long
Dim Price As String
Dim EPS As String
Dim PE As String
' Set the URL for Yahoo Finance
URL = "https://finance.yahoo.com/"
' Set the list of stocks to search for
StockList = Array("GOOGL", "PFE", "MMM", "GS")
' Create an instance of Microsoft Edge
Set Edge = CreateObject("Microsoft.Edge.Application")
' Make the browser visible
Edge.Visible = True
' Navigate to Yahoo Finance
Edge.Navigate URL
' Wait for the page to load
Do While Edge.Busy Or Edge.readyState < 4
DoEvents
Loop
' Loop through the list of stocks
For i = 0 To UBound(StockList)
' Search for the stock symbol
Edge.Document.querySelector("input[aria-label='Search']").Value = StockList(i)
Edge.Document.querySelector("button[type='submit']").Click
' Wait for the search results to load
Do While Edge.Busy Or Edge.readyState < 4
DoEvents
Loop
' Extract the price, EPS, and P/E ratio
Price = Edge.Document.querySelector("span[data-reactid='50']").innerText
EPS = Edge.Document.querySelector("td[data-test='EPS_RATIO-value']").innerText
PE = Edge.Document.querySelector("td[data-test='PE_RATIO-value']").innerText
' Display the results in a message box
MsgBox StockList(i) & vbCrLf & "Price: " & Price & vbCrLf & "EPS: " & EPS & vbCrLf & "P/E Ratio: " & PE
Next i
' Quit Microsoft Edge
Edge.Quit
End Sub
Sub GetStockInfo()
' Define variables
Dim Edge As Object
Dim URL As String
Dim StockList As Variant
Dim i As Long
Dim Price As String
Dim EPS As String
Dim PE As String
' Set the URL for Yahoo Finance
URL = "https://finance.yahoo.com/"
' Set the list of stocks to search for
StockList = Array("GOOGL", "PFE", "MMM", "GS")
' Create an instance of Microsoft Edge
Set Edge = CreateObject("Microsoft.Edge.Application")
' Make the browser visible
Edge.Visible = True
' Navigate to Yahoo Finance
Edge.Navigate URL
' Wait for the page to load
Do While Edge.Busy Or Edge.readyState < 4
DoEvents
Loop
' Loop through the list of stocks
For i = 0 To UBound(StockList)
' Search for the stock symbol
Edge.Document.querySelector("input[aria-label='Search']").Value = StockList(i)
Edge.Document.querySelector("button[type='submit']").Click
' Wait for the search results to load
Do While Edge.Busy Or Edge.readyState < 4
DoEvents
Loop
' Extract the price, EPS, and P/E ratio
Price = Edge.Document.querySelector("span[data-reactid='50']").innerText
EPS = Edge.Document.querySelector("td[data-test='EPS_RATIO-value']").innerText
PE = Edge.Document.querySelector("td[data-test='PE_RATIO-value']").innerText
' Display the results in a message box
MsgBox StockList(i) & vbCrLf & "Price: " & Price & vbCrLf & "EPS: " & EPS & vbCrLf & "P/E Ratio: " & PE
Next i
' Quit Microsoft Edge
Edge.Quit
End Sub