Creating a batch file that opens google chrome and puts input into the search box?

元气小坏坏 提交于 2020-01-06 02:51:05

问题


So I am just playing with batch files and was curious if it was possible to create a batch file that opens the google browser and without typing into the search box, a variable from my batch file gets put into the search box. Anyone know if that's possible? Thanks.

@echo off
cd c:\program files (x86)\google\application
start chrome.exe www.youtube.com

I can open the web browser, I can even change the code to store the variable, but need to know how to send that variable to the search engine. Youtube i just the website i left it at.


回答1:


If you use google as search engine, try to pass the keyword like this :

@echo off
start "" chrome.exe www.google.com#q=batch

and if you want add more than a keyword just add the sign +

@echo off
start "" chrome.exe www.google.com#q=batch+vbscript+HTA



回答2:


You could send raw HTTP request as follows:

start "" "c:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "https://www.youtube.com/results?search_query=simon's cat"

Below is possible approach how-to make it more readable in a batch script (non-systematic approach, as e.g. site variable joins together protocol and host name). Use appropriate value of engine variable for a particular host (as it could vary for different servers):

@ECHO OFF >NUL
SETLOCAL EnableExtensions EnableDelayedExpansion
set "chromepath=c:\Program Files (x86)\Google\Chrome\Application" path to chrome
set "site=https://www.youtube.com"
set "engine=results?search_query"                              
set "search=simon's cat"                                       string to search
start "" "!chromepath!\chrome.exe" "!site!/!engine!=!search!"

Delayed expansion used as any variable in above code could contain cmd poisonous characters.



来源:https://stackoverflow.com/questions/32407919/creating-a-batch-file-that-opens-google-chrome-and-puts-input-into-the-search-bo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!