• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Wanna have my vba code little modified to serve my purpose

shahin

Active Member
Hi sir, Chihiro! Hope you are doing well. Sorry to start a thread which I don't intend to prolong as it seems to be. Struggling a lot, I made a parser in which when I search a random name then its actual name and link are parsed very smoothly using google. I then modified the code for the purpose of going deep to find the name, link and PHONE NUMBER of a certain search. The name I used for google search is already embedded in Row 3 Column 1 in the spreadsheet I have attached. I cemented that only name (yellowpage) in the sheet because I worked with its link only. Now, my question is: whether it is possible to parse the phone number of any search i make because going to the link, i wanna parse phone number from, i could see that different websites are made with differently stratified elements. So it shouldn't work for different searches If the elements are written for a particular search. Then how the commercially made parsers do the magic? Here is why I get confused. Any thought of yours will be my blessing. Btw, attaching two files. First one is for customized search I have embedded already and second one is for random search you make . Thanks sir.

Customized One:
Code:
Sub GoogleSearch()

Dim http As New MSXML2.XMLHTTP60, html As New HTMLDocument, hmm As New HTMLDocument
Dim topics As Object, post As Object, link As Object, posts As Object
Dim url As String, z As String
Dim i As Long, LRow As Long

LRow = Range("A" & Rows.Count).End(xlUp).Row

For i = 3 To LRow

url = "https://www.google.co.in/search?q=" & Cells(i, 1)

http.Open "GET", url, False
http.setRequestHeader "Content-Type", "text/xml"
http.send

html.body.innerHTML = http.responseText

Set topics = html.getElementById("rso")
Set post = topics.getElementsByTagName("H3")(0)
Set link = post.getElementsByTagName("a")(0)

Cells(i, 2) = link.innerText
Cells(i, 3) = link.href
z = link.href

    http.Open "GET", z, False
    http.send
    hmm.body.innerHTML = http.responseText
   
    Set posts = hmm.getElementsByClassName("phone")
    Cells(i, 4) = posts(0).innerText

Next i
End Sub


For Random Search:

Code:
Sub GoogleSearch()

Dim http As New MSXML2.XMLHTTP60, html As New HTMLDocument, hmm As New HTMLDocument
Dim topics As Object, post As Object, link As Object, posts As Object
Dim url As String, z As String
Dim i As Long, LRow As Long

LRow = Range("A" & Rows.Count).End(xlUp).Row

For i = 3 To LRow

url = "https://www.google.co.in/search?q=" & Cells(i, 1)

http.Open "GET", url, False
http.setRequestHeader "Content-Type", "text/xml"
http.send

html.body.innerHTML = http.responseText

Set topics = html.getElementById("rso")
Set post = topics.getElementsByTagName("H3")(0)
Set link = post.getElementsByTagName("a")(0)

Cells(i, 2) = link.innerText
Cells(i, 3) = link.href

Next i
End Sub
 

Attachments

  • Customized.xlsm
    19.2 KB · Views: 0
  • Random Search.xlsm
    18.9 KB · Views: 0
Back
Top