Hello pari9485,
The following macros have been added to the attached workbook. There are in Module1 of the VBA project. A button has been added to the sheet to run the macro.
Module1 Macros
Function GetReviewsCount(ByVal URL As String) As Variant
Dim htmlDoc As Object
Dim htmlSpan As Object
Dim PageSrc As String
PageSrc = ""
With CreateObject("MSXML2.XMLHTTP")
.Open "GET", URL, True
.Send
While .readyState <> 4: DoEvents: Wend
' Check for any connection errors. Put the error info in cells A4:B4.
If .statusText <> "OK" Then
MsgBox "ERROR" & .Status & " - " & .statusText, vbExclamation
Exit Function
End If
PageSrc = .ResponseText
End With
' Create an empty HTML Document and load it with the PageSource.
Set htmlDoc = CreateObject("htmlfile")
htmlDoc.Open URL:="text/html", Replace:=False
' NOTE: This will check if cookies are enabled and prompt you if they aren't.
htmlDoc.write PageSrc
For Each htmlSpan In htmlDoc.getElementsByTagName("span")
If htmlSpan.ClassName = "partner-reviews-count" Then
If htmlSpan.NodeType = 1 Then
GetReviewsCount = Val(htmlSpan.innerHTML)
Exit Function
End If
End If
Next htmlSpan
GetReviewsCount = "No Review"
End Function
Sub Macro1()
Dim Cell As Range
Dim EndRow As Long
Dim Rng As Range
Dim Wks As Worksheet
Set Wks = ActiveSheet
Set Rng = Wks.Range("A2")
EndRow = Wks.Cells(Rows.Count, "A").End(xlUp).Row
If EndRow < Rng.Row Then Exit Sub Else Set Rng = Rng.Resize(EndRow - Rng.Row + 1, 1)
For Each Cell In Rng
Cell.Offset(0, 1) = GetReviewsCount(Cell)
Next Cell
End Sub
Bookmarks