6.13如何整合多个搜索引擎为自己所用

如何整合多个搜索引擎为自己所用

【实例描述】
搜索是获取网络信息的重要方法。本例通过一个简单的页面,学习如何整合多个搜索引擎为自己所用。
【实现代码】

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>标题页</title>
</head>
<body>
<form Name="InputForm">
<div align="center"><center><p>
<script language="JavaScript">
var FirstForm;
function StartSearch()
{
//使用隐藏控件保存用户输入的查询参数
document.forms[FirstForm+document.InputForm.SearchSelect.
selectedIndex].elements[0].value=document.InputForm.SearchWords.value;
//提交查询参数到指定网站
document.forms[FirstForm+document.InputForm.SearchSelect.selectedIndex].submit();
}
</script>
<span style="font-size: 9pt">查找内容:</span>
<input name="SearchWords" type="text" size="21" style=" margin-left: 1px"><br>
<span style="font-size: 9pt">搜索引擎:</span>
<select Name="SearchSelect" size="1" >
<option selected>英文Yahoo</option>
<option value="Google搜索">中文Google</option>
<option value="百度搜索">百度中文搜索</option>
</select><br>
<input type="button" value=" 开始查找 " onClick="StartSearch()">
<script language="JavaScript">
FirstForm=document.forms.length
</script></p>
</center></div>
</form>
<form action="http://search.yahoo.com/bin/search" method="get">
<input type="hidden" name="p" value>
</form>
<form action="http://www.google.com/search">
<input type="hidden" name="q" value>
</form>
<form action="http://www.baidu.com/s">
<input type="hidden" name="wd" value>
</form>
</body>
</html>

【运行效果】
整合的搜索引擎的运行效果如图6-12所示。打开的搜索结果页如图6-13所示,注意其地址栏的搜索参数,如果搜索内容为中文,则会被编码化。

图6-12 整合的搜索引擎的运行效果 图6-13 搜索结果页
【难点剖析】
本例的重点是在页面中添加多个form,然后使用form的“action”方法提交当前页面到搜索页面。在提交时要注意修改搜索参数,因为不同的搜索引擎,其搜索参数不同。如本例中google的搜索参数为“q”,百度的搜索参数为“wd”。


自己做的例子如下

0905.jsp

<html xmlns="http://www.w3.org/1999/xhtml" >
<%@ page language="java" pageEncoding="GBK"%>
<head>
<script type="text/javascript" src="0905.js"></script>
<title>标题页</title>

</head>

<body>

<form Name="InputForm">

<div align="center"><center><p>


<span style="font-size: 9pt">查找内容:</span>

<input name="SearchWords" type="text" size="21" style=" margin-left: 1px"><br>

<span style="font-size: 9pt">搜索引擎:</span>

<select Name="SearchSelect" size="1" >

<option selected>英文Yahoo</option>

<option value="Google搜索">中文Google</option>

<option value="百度搜索">百度中文搜索</option>

</select><br>

<input type="button" value=" 开始查找 " onClick="StartSearch()">

<script language="JavaScript">

FirstForm=document.forms.length

</script></p>

</center></div>

</form>

<form action="http://search.yahoo.com/bin/search" method="get">

<input type="hidden" name="p" value>

</form>

<form action="http://www.google.com/search">

<input type="hidden" name="q" value>

</form>

<form action="http://www.baidu.com/s">

<input type="hidden" name="wd" value>

</form>

</body>

</html>


0905.js

var FirstForm;
function StartSearch() {
//使用隐藏控件保存用户输入的查询参数
document.forms[FirstForm + document.InputForm.SearchSelect.selectedIndex].elements[0].value = document.InputForm.SearchWords.value;
//提交查询参数到指定网站
document.forms[FirstForm + document.InputForm.SearchSelect.selectedIndex].submit();
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值