Navigate to second page on webpage

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,395
How can I navigate to the second page of a webpage?


Suppose I want to go to the second page of the questions webpage on mrexcel:

Rich (BB code):
    Dim IE As SHDocVw.InternetExplorer
    Set IE = New SHDocVw.InternetExplorer

    IE.Visible = True
    IE.navigate "https://www.mrexcel.com/forum/excel-questions/"

I right click on the 2, choose Inspect Element and see this:

Rich (BB code):
<a title="Show results 21 to 40 of 3,150" href="https://www.mrexcel.com/forum/excel-questions/index2.html">2</a>

What can I do with this?


I tried:


Rich (BB code):
IE.Document.queryselector("a title="Show results 21 to 40 of 3,150" href="https://www.mrexcel.com/forum/excel-questions/index2.html">2").Click


but it doesn't even compile.


Thanks
 
Last edited:

Some videos you may like

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
6,624
It depends on the web site. For MrExcel, directly:
Code:
IE.Navigate "https://www.mrexcel.com/forum/excel-questions/index2.html"

Or indirectly, loop through IE.Document.Links (each link is a HTMLAnchorElement) looking for the link with innerText="2", or href containing "index2", or title containing "Show results 21 to 40", etc, then:
Code:
foundLink.Click
 

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,395
It depends on the web site. For MrExcel, directly:
Code:
IE.Navigate "https://www.mrexcel.com/forum/excel-questions/index2.html"

Or indirectly, loop through IE.Document.Links (each link is a HTMLAnchorElement) looking for the link with innerText="2", or href containing "index2", or title containing "Show results 21 to 40", etc, then:
Code:
foundLink.Click

Thanks for the response.

What if I want every page?

Since I have no idea how many pages there are in total, I can't look for index2, index3, etc.

How would I loop through each one to extract the data?
 
Last edited:

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
6,624
Again, it depends on the web site. One way might be:
Code:
Dim page As Long
For page = 1 To 10
    IE.Navigate "http://www.site.com/index" & page & ".html"
    'Wait for page to load
    'Extract data
Next
Some sites have a 'Next Page' or similar link, so look for that using the method in my previous post, or getElementById, getElementsByClassName, etc., until the 'Next Page' link doesn't exist. Without knowing the URL I can't give specific code.
 

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
6,624

ADVERTISEMENT

I tried to reply to your PM, but you've reached your message quota.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,311
Messages
5,600,886
Members
414,414
Latest member
neil_c

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
Top