Web scraping not pasting values in the order they appear on the page.

sdoppke

Well-known Member
Joined
Jun 10, 2010
Messages
647
Hi - I use the below code to scrape two sets of date from a web page. However the data is not pasting in the order it shows on the screen (web page). Is there something I am missing in my code?

Thanks in advance for any help.

SD

VBA Code:
f = 6
Set html = objIE.Document
Set elements = html.getElementsByClassName("nameLabel")
For Each element In elements
        Workbooks("RTM_Tool").Sheets("RTM").Cells(f, 12).Value = element.innerText
    f = f + 1
Next element

g = 6
Set html = objIE.Document
Set elements = html.getElementsByClassName("adherence")
For Each element In elements
        Workbooks("RTM_Tool").Sheets("RTM").Cells(g, 13).Value = element.innerText
    g = g + 1
Next element
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hi

  • Can you share a link to the page? You may have something as the table beneath there.
  • Try looping as shown below.

VBA Code:
For i = 0 To elements.Length – 1
     [e9]. offset(i)=elements(i).innertext
next
‘untested




Element3​
Element4​
Element1​
Element2​
 
Upvote 0

Forum statistics

Threads
1,214,625
Messages
6,120,598
Members
448,973
Latest member
ksonnia

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