PDA

View Full Version : Internet Explorer | Automate clicks on Google search results



Vallo
10-07-2010, 12:08 PM
Hello everybody :),

I'm new to the forum and I hope that you will be able to help me with what I'm trying to achieve.

I have recently started studying VBA for Excel and I'm writing a macro which, at the moment allows me to open Internet Explorer, open the web page "google.com", type a keyword on the search box and run the search. Everything fine here.

Now I'm trying to search for a specific link in the results and click on it (if it appears in the page), and here I'm having an issue..

I looked at the HTML code of the google results page, but the results are nowere to be seen (I cant see the actual links to the websites) so I don't know how to tell VBA how to look for the link to be searched.

For example: after searching the word "apple" in google, I want to search the link "Cake (band) - Wikipedia" and click on it.

Does anybody have an idea about what I'm talking about and how to do this thing please?

Many thanks in advance :)

Vallo
10-12-2010, 11:35 AM
Anybody can help please?

Vallo
10-12-2010, 11:41 AM
Anybody can help please?

Kenneth Hobs
10-12-2010, 12:04 PM
Posting your code usually helps us help you.

View source code for the resultant frame. Iterating through the links collection on that frame should meet your needs.

Vallo
10-14-2010, 05:18 AM
Many thanks Mr. Hobs,

I think that your suggestion of iterating through the links collection on that frame is exactly what I should do but I don't know what the code for that is.

Could you please tell me?

Many thanks in advance.

Here is the code that I have until now:



Sub ClickIE()

Dim ie As Object

Set ie = CreateObject("internetexplorer.application")

ie.Visible = True

ie.Navigate "google.com (cannot write the link here because I have too few posts)"

'wait for page to load
While ie.Busy
DoEvents
Wend

'write search keyword (for example apple)
ie.Document.getElementById("q").Value = "apple"

'click on search button
ie.Document.getElementById("btnG").Click

'wait for page to load
While ie.Busy
DoEvents
Wend

MsgBox "End macro"

End Sub

Kenneth Hobs
10-15-2010, 04:55 PM
I found one website that said that you can't use DOM methods for google's frame.

As such, a slower method would be needed. In this method, the text is selected, copied, and pasted to a sheet by the macro. The macro then checks each cell and if it contains the hyperlink, do what is needed. It then would delete the pasted text. If you want to pursue this method, let me know.

TWV
01-18-2015, 01:55 PM
I found one website that said that you can't use DOM methods for google's frame.

As such, a slower method would be needed. In this method, the text is selected, copied, and pasted to a sheet by the macro. The macro then checks each cell and if it contains the hyperlink, do what is needed. It then would delete the pasted text. If you want to pursue this method, let me know.