将html表单值传递给Google搜索查询 [英] Passing html form values to google search query

查看:51
本文介绍了将html表单值传递给Google搜索查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

旁白:在所有人都告诉我有关Google的自定义搜索引擎之前,直到现在我一直在使用它,但我发现很难为该搜索框设置样式,并且该搜索框在我的网站上损坏了.

SIDENOTE: Before everyone tells me about google's custom search engine, I have been using that until now but i find it really hard to style that search box and it broke on my website.

你好

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

I am trying to create a google search query that uses input from a HTML form. I want the search to be executed only on a specific site (for example reddit.com:elephant).

我遇到的问题是"reddit.com:"部分.我可以将大象"传递给查询,但是我尝试执行的所有操作似乎都忽略了第一部分.

The problem I have is the "reddit.com:" part. I am able to pass "elephant" to the query, but everything i tried seems to ignore the first part.

这是下面的代码

<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会在查询中传递.提交上面的表格后,我得到的链接看起来像这样

I tried it without the "site+q", tried putting "reddit.com%3A" in the action itself (action="https://www.google.com.au/search?reddit.com%3A+q"), but only the "q" gets passed in the query. the link i get after submitting the form above looks like this

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

我已经使用类似的链接在Google上进行了一些研究,而最有用的网站是 https://moz.com/blog/the-ultimate-guide-to-the-google-search-parameters ,但说实话,这让我感到非常困惑我在那里找不到任何可以帮助我的东西.它已经十岁了,所以我什至不确定那是否仍然有效.

I have done some research on google with building links like this, and the most useful site was this https://moz.com/blog/the-ultimate-guide-to-the-google-search-parameters , however, honestly, it made me really confused and i couldn't find anything there that would help me out. And it is 10 years old so I'm not even sure if thats still valid.

我想念什么?谁能指出我正确的方向?

What am i missing? can anyone point me in the right direction?

我也不确定此帖子的标签,请根据需要对其进行更正.

Also im not sure about the tag for this post, please correct it if needed.

提前谢谢

推荐答案

我发现了另一个正在询问我到底想要什么的线程:

I have found another thread that was asking exactly what i wanted here: Add Google search in web page

这是懒惰的代码段:

您只需要将form方法设置为"get",在要搜索的网站上添加一个额外的隐藏元素,它将自动将其粘贴到URL后面,如下所示:

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>

因为这是默认情况下HTML表单的工作方式

Because that is how HTML forms work by default

这篇关于将html表单值传递给Google搜索查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆