Is it possible to make a batch file which search a word in google and afterwords opens a specific web site?

For example when i run this script @echo off cd C:\Program Files\Internet Explorer iexplore http://www.google.bg/search?q=%search%+wedding photographer

It opens IE and search automatically "wedding photographer" I want, if it is possible, automatically to "land" at specific site http://example.com

10x in advanced!

  • Welcome to Super User! The answer to your question is, of course, yes, it's possible. But what is your specific question? What have you tried already? Where did you get stuck? Can you give a more specific example of what should be done with Google results? – slhck Nov 22 '16 at 15:12
  • Can you provide an exact example of something you would be trying to do? Do you mean search oranges and open the first link that appears? – Narzard Nov 22 '16 at 15:24
  • @Narzard well he didn't specify only the first link. so if you gave an answer that would open whichever link, first, second, third, then obviously that would answer his question – barlop Nov 22 '16 at 15:36
  • @barlop yeah, just wanted to get deeper into what he was trying to do – Narzard Nov 22 '16 at 16:22
  • I would like to open when you type oranges a specific web site, not the first, second or third... – Tihomir Yordanov Nov 23 '16 at 6:18

There are options for doing this:

  1. Selenium browser automation
  2. Phantom -- Headless web browser

You could try both of them and choose one based on your task requirements and your programming experience.

  • can you elaborate on the difference between those two? btw another option is wget to make an http request then try something like e.g. chrome http://www.blah.com – barlop Nov 22 '16 at 15:14

Just wrote this powershell script up that takes a user input, searches google with chrome, tabs to the first link and then opens it. The loop can be modified to select any element on the page (changing the number 17 in this example).

Copy this into notepad and save as a .ps1, then right click on it and open it with powershell. When PS opens, it will ask for a search term. Type oranges

[void] [System.Reflection.Assembly]::LoadWithPartialName("'System.Windows.Forms")
$userSearch = Read-Host -Prompt 'Insert Search Term'
[System.Diagnostics.Process]::Start("chrome.exe","www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=" + $userSearch)
Start-Sleep -s 3

For ($i=0; $i -le 17; $i++)
    Start-Sleep -m 150
Start-Sleep -s 1

There is another way by using IE and more of the .net api to grab elements off the page by ID by google search results arent really conducive to that. If you were scraping data off of a specific page that had static info, it would be more ideal to use. Real flexibility comes with using Selenium though, but that takes some programming experience. You should just be able to edit this code as is and figure out how to get it to do what you want.

Edit: Pre-requisite - have chrome.

Here is another way to do it with IE. This will prompt for a search term, then open one tab that uses "I'm feeling Lucky" to go to the best page and a second tab with regular search results. Save as a .ps1.

$url1 = "http://www.google.com/search?q="
$url2 = "&btnI"
$userSearch = Read-Host -Prompt 'Insert Search Term'
$ie = New-Object -com internetexplorer.application; 
$ie.visible = $true; 
$ie.navigate($url1 + $userSearch + $url2);
$ie.navigate($url1 + $userSearch , 2048)
  • Something is not working right. When i runs the script in powershell, it just closes the CMD... It doesn't stop to ask me what i should search – Tihomir Yordanov Nov 23 '16 at 6:22
  • I will check on this when I get home and give you more solutions as well – Narzard Nov 23 '16 at 6:30
  • @TihomirYordanov added another method. Try that one – Narzard Nov 23 '16 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.