Web Scraping with VBA - problems clicking a button

corollary

New Member
Joined
May 31, 2014
Messages
18
I've got most of a scraping code figured out - I'm trying to get the 1st and 2nd halfs from a link like this: Lafayette Leopards vs. Villanova Wildcats - Box Score - November 11, 2016 | FOX Sports.

The link initially defaults to the box score - but I'm able to code in clicking on the 'play-by-play' to bring up the html code I need. Where I'm having a problem is getting to the 2nd half - I can't figure out how to encode clicking on the '2' in the link. It almost looks to be not a problem of clicking, but of changing the class of one of the elements. Please let me know if you can help - I'm a little bit stuck here.

Here are the relevant bits of code - omitted the scraping part, because it's not the piece I'm having trouble with.



Code:
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = False


            site = Range("h1").Value
            
            With IE
                .Visible = True
                .navigate site
                .Top = 50
                .Left = 530
                .Height = 400
                .Width = 400
        
            Do Until Not IE.Busy And IE.readyState = 4
                DoEvents
            Loop
                
            End With


   
            ID = "wisbb_bsCPbpSmallTable"
            
            Set htmldoc = IE.document 'Document webpage
            
            htmldoc.getElementsByClassName("wisbb_shortName").Item(2).Click 'Gets me to play-by-play'
            htmldoc.getElementsByClassName("wisfb_bsPbpSelected").Item(1).Click 'No variation of this (changing the item, the class name, etc.) has gotten me to the second half

Appreciate any help I can get - thanks.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Try...

Code:
    HTMLDoc.getElementsByClassName("wisbb_bsPbpSelector").Item(0).getElementsByTagName("a").Item(1).Click

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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