Sub Get_Links_Prayer_Times()
Dim v, html As MSHTML.HTMLDocument, ws As Worksheet, post As Object, sURL As String, nURL As String, x As Integer, i As Long, r As Long, c As Long
Application.DisplayAlerts = False
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Sheet1" Then ws.Delete
Next ws
Application.DisplayAlerts = True
For x = 65 To 66
sURL = "https://www.prayer-times.info/en/filter-" & Chr(x) & "/"
Set ws = Worksheets.Add(After:=Worksheets(Worksheets.Count))
ws.Name = Chr(x)
Set html = GetHTML(sURL)
Set post = html.querySelectorAll("#country_list li")
c = 1
With post
If .Length > 0 Then
For i = 0 To .Length - 1
r = r + 1
ws.Cells(1, c).Value = Trim(Replace(.Item(i).innerText, vbCrLf, ""))
ws.Cells(1, c + 1).Value = .Item(i).getElementsByTagName("a")(0).getAttribute("href")
v = GetCities(CStr(ws.Cells(1, c + 1).Value))
ws.Cells(2, c).Resize(UBound(v, 1), UBound(v, 2)).Value = v
c = c + 2
Next i
End If
End With
ws.Columns.AutoFit
Next x
MsgBox "Done...", 64, "YasserKhalil Chandoo"
End Sub
Function GetCities(ByVal sURL As String)
Dim html As MSHTML.HTMLDocument, post As Object, i As Long
Set html = GetHTML(sURL)
Set post = html.querySelectorAll("#city_list li")
With post
ReDim a(1 To .Length, 1 To 2)
For i = 0 To .Length - 1
a(i + 1, 1) = Split(.Item(i).innerText)(UBound(Split(.Item(i).innerText)))
a(i + 1, 2) = .Item(i).getElementsByTagName("a")(0).getAttribute("href")
Next i
End With
GetCities = a
End Function
Function GetHTML(ByVal sURL As String) As HTMLDocument
Dim http As MSXML2.XMLHTTP60, html As MSHTML.HTMLDocument
Set http = New MSXML2.XMLHTTP60
Set html = New MSHTML.HTMLDocument
With http
.Open "Get", sURL, False
.send
html.body.innerHTML = .responseText
End With
Set GetHTML = html
End Function