jamescooper
Well-known Member
- Joined
- Sep 8, 2014
- Messages
- 840
Hello,
I am trying to pull the data from this link:
http://greyhoundbet.racingpost.com/#card/race_id=1592960&r_date=2018-02-27&tab=form
My code so far below, gives all the URLs and loops through, placing them in sheet1 below one another.
I only require the links of each dog in the form, so there are 6 links which for the above URL are:
http://greyhoundbet.racingpost.com/#dog/race_id=1592960&r_date=2018-02-27&dog_id=491247
http://greyhoundbet.racingpost.com/#dog/race_id=1592960&r_date=2018-02-27&dog_id=503888
http://greyhoundbet.racingpost.com/#dog/race_id=1592960&r_date=2018-02-27&dog_id=516549
http://greyhoundbet.racingpost.com/#dog/race_id=1592960&r_date=2018-02-27&dog_id=516104
http://greyhoundbet.racingpost.com/#dog/race_id=1592960&r_date=2018-02-27&dog_id=494253
http://greyhoundbet.racingpost.com/#dog/race_id=1592960&r_date=2018-02-27&dog_id=512296
Does anyone have any idea how I would adapt my code, the href appears to be linked in an 'a class' called "gh DogName" when I inspect the code.
As ever - many thanks.
I am trying to pull the data from this link:
http://greyhoundbet.racingpost.com/#card/race_id=1592960&r_date=2018-02-27&tab=form
My code so far below, gives all the URLs and loops through, placing them in sheet1 below one another.
I only require the links of each dog in the form, so there are 6 links which for the above URL are:
http://greyhoundbet.racingpost.com/#dog/race_id=1592960&r_date=2018-02-27&dog_id=491247
http://greyhoundbet.racingpost.com/#dog/race_id=1592960&r_date=2018-02-27&dog_id=503888
http://greyhoundbet.racingpost.com/#dog/race_id=1592960&r_date=2018-02-27&dog_id=516549
http://greyhoundbet.racingpost.com/#dog/race_id=1592960&r_date=2018-02-27&dog_id=516104
http://greyhoundbet.racingpost.com/#dog/race_id=1592960&r_date=2018-02-27&dog_id=494253
http://greyhoundbet.racingpost.com/#dog/race_id=1592960&r_date=2018-02-27&dog_id=512296
Does anyone have any idea how I would adapt my code, the href appears to be linked in an 'a class' called "gh DogName" when I inspect the code.
As ever - many thanks.
Code:
Sub Dog_URLs()
Dim ie As InternetExplorer
Dim html As HTMLDocument
Dim ElementCol As Object
Dim Link As Object
Dim erow As Long
Dim DLine As Range
Dim LastRow As Long
Application.Calculation = xlCalculationManual
Sheets("Sheet1").Select
LastRow = Sheets("Races").Range("C" & Rows.Count).End(xlUp).row
For Each DLine In Sheets("Races").Range("C1:C" & LastRow)
Set ie = New InternetExplorer
ie.Visible = True
With ie
.Navigate DLine.Value
Do While ie.ReadyState <> READYSTATE_COMPLETE
Application.StatusBar = "Trying to go to website…"
DoEvents
Loop
Application.Wait Now + TimeValue("00:00:01")
Set html = ie.Document
Set ElementCol = html.getElementsByTagName("a")
For Each Link In ElementCol
erow = Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Offset(erow, erow).row
Cells(erow, 2).Value = Link
Cells(erow, 2).Columns.AutoFit
Next
ie.Quit
Set ie = Nothing
End With
Next DLine
Application.Calculation = xlCalculationAutomatic
End Sub