Jump to content

How to get the first link in google result?


Recommended Posts

Have you had a look at the IE function reference?

You'll start with:

#include <IE.au3>

_IECreate("http://www.google.com")

Give something a try, and if you have any questions post your code. ;)

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

$getLink is an object collection if _IELinkGetCollection returns anything. Are you saying it's not a collection?

You should try the script here to see if you're getting anything returned. @extended will contain the number of links it finds.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

This should help you out a bit:

#include <IE.au3>

Local $keyword = "ABC"
Local $googlesearch = "www.google.com/search?q=" & $keyword

$oIE = _IECreate($googlesearch)
_IELinkGetCollection($oIE)

Local $oLinks = _IELinkGetCollection($oIE)
Local $iNumLinks = @extended

MsgBox(0, "Link Info", $iNumLinks & " links found")
For $oLink In $oLinks
    MsgBox(0, "Link Info", $oLink.href)
Next
Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Thanks all! 

Here's my code:

#include <IE.au3>

Local $keyword = 'ABC "DEF" GHK'
$key1 = StringReplace($keyword, " ", "+")
$key2 = StringReplace($key1, '"', "%22")
Local $googlesearch = "www.google.com/search?q=" & $key2

_IELoadWaitTimeout(5000)
$oIE = _IECreate($googlesearch, 0, 1, 1)
_IELinkGetCollection($oIE)

Local $oLinks = _IELinkGetCollection($oIE)

Local $sTxt
For $oLink In $oLinks
   if StringInStr($oLink.href, "url?url=") Then
      $link1 = StringReplace($oLink.href, "http://www.google.com/url?url=", "")
      $link2 = StringSplit($link1, "&rct=", 1)
      if StringInStr($link2[1], "https://www.google.com/url?url=") Then
         $link3 = StringReplace($link2[1], "https://www.google.com/url?url=", "")
      Else
         $link3 = $link2[1]
      EndIf
      $sTxt &= $link3 & @CRLF
   EndIf
Next
MsgBox(0, "LIST", $sTxt)

@jdelaney: I've searched some topic like: '?do=embed' frameborder='0' data-embedContent>>

But when I run that script, it show me an error "Unknown function name"

Edited by langthang084
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...