Super User Asked by Tihomir Yordanov on March 2, 2021
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 FilesInternet 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!
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++)
{
[System.Windows.Forms.SendKeys]::SendWait("{TAB}")
Start-Sleep -m 150
}
Start-Sleep -s 1
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
pause
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)
Answered by Narzard on March 2, 2021
There are options for doing this:
You could try both of them and choose one based on your task requirements and your programming experience.
Answered by Fedor Dikarev on March 2, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP