YasserKhalil
Well-Known Member
Hello everyone
I am working on the following code and I am stuck at one point. I have commented that part
The line that I am stuck at is
How to assign or refer to the email element ..?
I am working on the following code and I am stuck at one point. I have commented that part
Code:
Sub MyTest()
Const sURL As String = "https://www.gelbeseiten.de/Suche/Ambulante%20Pflegedienste/Bundesweit"
Dim http As MSXML2.XMLHTTP60, html As HTMLDocument
Set http = New MSXML2.XMLHTTP60
Set html = New MSHTML.HTMLDocument
'sURL = bURL & sASIN
With http
.Open "Get", sURL, False
.send
html.body.innerHTML = .responseText
'ExportHTML .responseText
End With
Dim post As Object
Set post = html.querySelectorAll(".mod-Treffer")
Dim i As Long, r As Long
Range("A1").Resize(1, 3).Value = Array("Title", "Phone", "Email")
r = 2
'Debug.Print html.getElementById("#transform_wrapper").getElementsByTagName("article")(0).innerHTML
For i = 0 To post.Length - 1
Cells(r, 1).Value = post.Item(i).getElementsByTagName("h2")(0).innerText
Cells(r, 2).Value = post.Item(i).getElementsByTagName("Address")(0).getElementsByTagName("p")(1).innerText
'I am stuck with extracting the email
Dim emailObj As Object
If r = 3 Then Stop
Dim aNodeList As Object, j As Long
'---------------------------------------------------------
'I AM STUCK AT THIS LINE
Set aNodeList = post.Item(i).querySelectorAll(".contains-icon-email")(0)
'---------------------------------------------------------
For j = 0 To aNodeList.Length - 1
Debug.Print aNodeList.Item(j).innerText '< === as check
Next j
'Set emailObj = post.Item(i).getElementsByClassName("contains-icon-email")
'Set emailObj = post.Item(i).getElementsByTagName("a")(1)
' If Not emailObj Is Nothing Then
' If InStr(post.Item(i).getElementsByTagName("a")(1).href, "mailto:") Then
' Cells(r, 3).Value = Split(Split(post.Item(i).getElementsByTagName("a")(1).href, "mailto:")(1), "?")(0)
' End If
End If
Set emailObj = Nothing: r = r + 1
Next i
'Stop
'GetMerchantURL = Replace(html.getElementById("merchant-info").getElementsByTagName("a")(0).href, "about:", "https://www.amazon.de")
Set http = Nothing: Set html = Nothing
End Sub
The line that I am stuck at is
Code:
Set aNodeList = post.Item(i).querySelectorAll(".contains-icon-email")(0)
How to assign or refer to the email element ..?