Skip to main content
Code Review

Return to Question

Tweeted twitter.com/StackCodeReview/status/1501392350450442247
Fixed code formatting and other improvements
Source Link

Scraping takes long to obtain table contentscampsite availability from a webpage using vba with selenium

I wrote some code to extract the information from a table, but it takes an extremely long time. The

The table is in the format of a calendar. I need the information on an Excel sheet with column 1 as the day number and column 2 as the accommodation type. On the accommodation type, I only want the "Camp" types and the number of available units to show. I’m sure there will be a better way to loop through the table. AnnyAny help will be appreciated.

Here is my code:

"***DimDim driver As New WebDriver, i As Integer, mysheet As Worksheet 
Dim ele As WebElement 
Set driver = New EdgeDriver 
Application.ScreenUpdating = False 
driver.Start "edge" 
driver.Get "http://www.sanparks.org/reservations/accommodation/calendar-month/park/26/camp/41/date/2022-07-01"
Application.Wait Now + TimeValue("00:00:05")
Set mysheet = Sheets("Sheet1")
i = 7
eRow = Sheet1.Cells(Rows.Count, 3).End(xlUp).Offset(7, 0).Row
For Each ele In driver.FindElementsByClass("day")
If ele.FindElementByCss("span").Text <> "" Then
 mysheet.Cells(i, 2).Value = ele.FindElementByCss("span").Text
 On Error Resume Next
 If Mid(ele.FindElementByClass("bold-name").Text, 1, 4) = "Camp" Then 'AccommodationType
 mysheet.Cells(i, 3).Value = ele.FindElementByClass("bold-name").Text & " " & ele.FindElementByClass("unit-numbers").Text
 
 End If
 On Error GoTo 0
 i = i + 1
End If
Next ele***"ele

Scraping takes long to obtain table contents from a webpage using vba with selenium

I wrote some code to extract the information from a table, but it takes extremely long. The table is in the format of a calendar. I need the information on an Excel sheet with column 1 as the day number and column 2 as the accommodation type. On the accommodation type, I only want the "Camp" types and the number of available units to show. I’m sure there will be a better way to loop through the table. Anny help will be appreciated.

Here is my code:

"***Dim driver As New WebDriver, i As Integer, mysheet As Worksheet 
Dim ele As WebElement 
Set driver = New EdgeDriver 
Application.ScreenUpdating = False 
driver.Start "edge" 
driver.Get "http://www.sanparks.org/reservations/accommodation/calendar-month/park/26/camp/41/date/2022-07-01"
Application.Wait Now + TimeValue("00:00:05")
Set mysheet = Sheets("Sheet1")
i = 7
eRow = Sheet1.Cells(Rows.Count, 3).End(xlUp).Offset(7, 0).Row
For Each ele In driver.FindElementsByClass("day")
If ele.FindElementByCss("span").Text <> "" Then
 mysheet.Cells(i, 2).Value = ele.FindElementByCss("span").Text
 On Error Resume Next
 If Mid(ele.FindElementByClass("bold-name").Text, 1, 4) = "Camp" Then 'AccommodationType
 mysheet.Cells(i, 3).Value = ele.FindElementByClass("bold-name").Text & " " & ele.FindElementByClass("unit-numbers").Text
 
 End If
 On Error GoTo 0
 i = i + 1
End If
Next ele***"

Scraping campsite availability from a webpage using vba with selenium

I wrote some code to extract the information from a table, but it takes an extremely long time.

The table is in the format of a calendar. I need the information on an Excel sheet with column 1 as the day number and column 2 as the accommodation type. On the accommodation type, I only want the "Camp" types and the number of available units to show. I’m sure there will be a better way to loop through the table. Any help will be appreciated.

Here is my code:

Dim driver As New WebDriver, i As Integer, mysheet As Worksheet 
Dim ele As WebElement 
Set driver = New EdgeDriver 
Application.ScreenUpdating = False 
driver.Start "edge" 
driver.Get "http://www.sanparks.org/reservations/accommodation/calendar-month/park/26/camp/41/date/2022-07-01"
Application.Wait Now + TimeValue("00:00:05")
Set mysheet = Sheets("Sheet1")
i = 7
eRow = Sheet1.Cells(Rows.Count, 3).End(xlUp).Offset(7, 0).Row
For Each ele In driver.FindElementsByClass("day")
If ele.FindElementByCss("span").Text <> "" Then
 mysheet.Cells(i, 2).Value = ele.FindElementByCss("span").Text
 On Error Resume Next
 If Mid(ele.FindElementByClass("bold-name").Text, 1, 4) = "Camp" Then 'AccommodationType
 mysheet.Cells(i, 3).Value = ele.FindElementByClass("bold-name").Text & " " & ele.FindElementByClass("unit-numbers").Text
 
 End If
 On Error GoTo 0
 i = i + 1
End If
Next ele
Source Link
Nelj
  • 41
  • 5

Scraping takes long to obtain table contents from a webpage using vba with selenium

I wrote some code to extract the information from a table, but it takes extremely long. The table is in the format of a calendar. I need the information on an Excel sheet with column 1 as the day number and column 2 as the accommodation type. On the accommodation type, I only want the "Camp" types and the number of available units to show. I’m sure there will be a better way to loop through the table. Anny help will be appreciated.

Here is my code:

"***Dim driver As New WebDriver, i As Integer, mysheet As Worksheet 
Dim ele As WebElement 
Set driver = New EdgeDriver 
Application.ScreenUpdating = False 
driver.Start "edge" 
driver.Get "http://www.sanparks.org/reservations/accommodation/calendar-month/park/26/camp/41/date/2022-07-01"
Application.Wait Now + TimeValue("00:00:05")
Set mysheet = Sheets("Sheet1")
i = 7
eRow = Sheet1.Cells(Rows.Count, 3).End(xlUp).Offset(7, 0).Row
For Each ele In driver.FindElementsByClass("day")
If ele.FindElementByCss("span").Text <> "" Then
 mysheet.Cells(i, 2).Value = ele.FindElementByCss("span").Text
 On Error Resume Next
 If Mid(ele.FindElementByClass("bold-name").Text, 1, 4) = "Camp" Then 'AccommodationType
 mysheet.Cells(i, 3).Value = ele.FindElementByClass("bold-name").Text & " " & ele.FindElementByClass("unit-numbers").Text
 
 End If
 On Error GoTo 0
 i = i + 1
End If
Next ele***"
lang-vb

AltStyle によって変換されたページ (->オリジナル) /