How to modify code to scrape data on a daily, weekly and monthly bases on websites

Corried

Board Regular
Joined
Dec 19, 2019
Messages
217
Office Version
  1. 2019
Platform
  1. Windows
  2. Web
Hello Excel supporters...

I am not sure if Worf or anyone in this forum can help me.

Below I have a file & code to scrape data from many links in investing.com

The trouble I am having is this:
On the web page. There is a "Time Frame" box list: Daily, Weekly & Monthly.
However, inspect the element. The box id for the "Time Frame" is id="data_interval", which holds the list for " Daily, Weekly & Monthly."

For some reason. I am not getting the code to give me data on the weekly and monthly bases. It only works for the daily bases.

How can I modify the code to work for all time frames and still maintain my end results in capturing only the latest "Date" and "Price"?...

On the excel worksheet. A dropdown list was created to change the time on the website...

If anyone is willing. Please view the file and code below to examine.

Thanks in advance

Cheers.

VBA Code:
Sub MMM()
LastRow = Cells(Rows.Count, 1).End(xlUp).Row
x = Timer
On Error Resume Next
'Application.ScreenUpdating = False
    With CreateObject("Selenium.ChromeDriver")
        .AddArgument "--headless"
        For i = 2 To LastRow
                 .Get Cells(i, 14)
                 .FindElementById("data_interval").AsSelect.SelectByText (Cells(1, 7).Value)
                  Cells(i, 10) = .FindElementById("curr_table").FindElementsByTag("tr")(2).FindElementsByTag("td")(1).Text
                  Cells(i, 9) = .FindElementById("curr_table").FindElementsByTag("tr")(2).FindElementsByTag("td")(2).Text
                  [N1].Value = Round((i - 2) / (LastRow - 2), 2)
'           [k1].Value = "Progress  : " & Round((i - 2) * 100 / (LastRow - 2), 0) & " %"
        Next
        .Quit
     End With
 y = Timer
' Application.ScreenUpdating = True
 MsgBox "Time:" & Round(y - x, 0) & "  secons"
End Sub

 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Problème résolu
Il n'y a rien de mal avec le code. J'ai fait une erreur en déplaçant certaines cellules. Cela a empêché la macro de fonctionner correctement.

Je suis désolé pour la cause de la gêne occasionnée
 
Upvote 0
Solution
Good to see you worked it out, but for the future please remember the following. :)

1612593225438.png
 
Upvote 0

Forum statistics

Threads
1,214,402
Messages
6,119,301
Members
448,885
Latest member
LokiSonic

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top