将 html 表单值传递给 google 搜索查询

Passing html form values to google search query

旁注:在每个人都告诉我 google 的自定义搜索引擎之前,我一直在使用它直到现在,但我发现很难设置搜索框的样式并且它在我的网站上损坏了。

你好

我正在尝试创建一个 google 搜索查询,它使用来自 HTML 表单的输入。我希望仅在特定站点上执行搜索(例如 reddit.com:elephant)。

我遇到的问题是 "reddit.com:" 部分。我可以将 "elephant" 传递给查询,但我尝试的一切似乎都忽略了第一部分。

下面是代码

<form method="get" action="https://www.google.com.au/search?site+q">
        <input type="hidden" name="site" value="reddit.com:">
        <input type="text" value="" name="q" id="query">
        <input type="submit" value="search">
 </form>

我在没有 "site+q" 的情况下尝试过,尝试将 "reddit.com%3A" 放入操作本身 (action="https://www.google.com.au/search?reddit.com%3A+q"),但只有 "q" 在查询中传递. link 我在提交上面的表格后得到的是这样的

https://www.google.com.au/search?site=reddit.com%3A&q=elephant

我对 google 做了一些研究,像这样构建 link,最有用的网站是这个 https://moz.com/blog/the-ultimate-guide-to-the-google-search-parameters,但是,老实说,这让我很困惑,我在那里找不到任何可以帮助我的东西。它已有 10 年历史,所以我什至不确定它是否仍然有效。

我错过了什么?谁能指出我正确的方向?

我也不确定这个 post 的标签,如果需要请更正它。

提前致谢

这样的构造怎么样:

<form role="search" method="get" action="https://www.google.com/search?q=site:reddit.com+x">
    <div class="search-control">
        <input type="search" id="site-search" name="x"
               placeholder="Search the site..."
               aria-label="Search through site content">
        <button>Search</button>
    </div>
</form>

我找到了另一个线程,它确切地询问了我在这里想要什么:Add Google search in web page

这是懒人的代码片段:

You just need to set the form method to "get", add one extra hidden element with the site you want to search and it will automatically paste it behind the URL as such:

<form action="https://google.com/search" method="get">
    <input type="hidden" name="sitesearch" value="http://acme.com" />
    <input type="text" name="q" />
</form>

Because that is how HTML forms work by default