0

I am getting a problem to scroll document in a proper position, also getting a problem to capture a proper detail in excel here is my Code please Sir suggest me where I am getting wrong

here i try with following code still getting some error

Public Sub GData()

    'On Error Resume Next

    Dim html As HTMLDocument
    Dim Re, Cr, cipherDict As Object
    Dim sResponse, cipherKey, Str, SG As String
    Dim myArr, RsltArr(14) As Variant
    
    Set Re = CreateObject("vbscript.regexp")
    Set Cr = CreateObject("MSXML2.XMLHTTP")
    Set cipherDict = CreateObject("Scripting.Dictionary")
    Set html = New HTMLDocument

    URL = "https://www.google.com/maps/place/Silky+Beauty+Salon/@22.2932632,70.7723656,17z/data=!3m1!4b1!4m5!3m4!1s0x3959ca1278f4820b:0x44e998d30e14a58c!8m2!3d22.2932632!4d70.7745543"
            With Cr
                .Open "GET", URL, False
                .setRequestHeader "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"
                .send
                sResponse = StrConv(.responseBody, vbUnicode)
                s = .responseText
            End With
    
    
    With html
        .body.innerHTML = sResponse
        title = .querySelector("section-hero-header-title-title").innerText
        phone = .querySelector("[data-item-id^=phone] [jsan*=text]").innerText
        webSite = .querySelector("[aria-label^=Website] [jsan*=text]").innerText
    End With
    
    datarw = ActiveSheet.Cells(ActiveSheet.Rows.Count, "A").End(xlUp).Row + 1
        ActiveSheet.Cells(datarw, 1).Value = title
        ActiveSheet.Cells(datarw, 5).Value = phone
        ActiveSheet.Cells(datarw, 7).Value = webSite
        ActiveSheet.Cells(datarw, 1).Select
        ActiveSheet.Rows(datarw).WrapText = False

End Sub

Lalit Patel
  • 115
  • 14
  • Where do you see tel numbers in the web results section? – QHarr Jan 30 '21 at 15:07
  • thanks Sir for your replay... there different possibility. some url have tel number some have website.. check the second ur which post in code , check thisw two url 1- https://goo.gl/maps/jZSS7MMQbbkKuyru5 2- https://g.page/silkybeautysalon?share – Lalit Patel Jan 30 '21 at 15:47
  • Do you mean the main result? There are no tel numbers shown in the `web results`sections of those two links. Nor email addresses. – QHarr Jan 30 '21 at 15:48
  • Please Sir look here I edit screenshot in my main question with tel no and website from this url g.page/silkybeautysalon?share – Lalit Patel Jan 30 '21 at 16:09
  • That is the main section and doesn't need scrolling. What is the problem with retrieving from there? – QHarr Jan 30 '21 at 16:35
  • the problem is to retrieving tel no and website.. as "ugiz4pqJLAG__text ugiz4pqJLAG__underline_on_hover" class name Item () is changing with different url... how to identify for tel no and web item(X) – Lalit Patel Jan 30 '21 at 16:59
  • sir I try with as you suggested. but still getting some error.. please look at my code here I edit my code in main question – Lalit Patel Jan 31 '21 at 05:27
  • you have changed the question. Please rollback the last edit to how it was and open a new question with the new problem. – QHarr Jan 31 '21 at 08:09

1 Answers1

1

Looks like you can use combinations of different combinators (^ starts with and * contains) to search for substrings in attributes on the page to get your target nodes. Using descendant combinators to specify the relationship between attributes being used for anchoring.

Test if matched node Is Not Nothing before attempting to access either an attribute value or .innerText

Dim phone as Object, webSite As Object, title As Object

Set title = ie.document.querySelector(".section-hero-header-title-title")
Set phone = ie.document.querySelector("[data-item-id^=phone] [jsan*=text]")
Set website = ie.document.querySelector("[aria-label^=Website] [jsan*=text]")

If Not phone Is Nothing Then 
    'clean phone.innerText as appropriate
End If

If Not website Is Nothing Then 
    'clean website.innerText as appropriate
End If

To get the appropriate protocol for the website address, if missing, you can use the cleaned website address you have in a regex to pull the protocol from earlier in the html where it sits in a script tag.


Read about

  1. css selectors: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors
  2. querySelector: querySelector and querySelectorAll vs getElementsByClassName and getElementById in JavaScript
QHarr
  • 83,427
  • 12
  • 54
  • 101