需求如下:
在winform中的一个TextBox中输入任何关键字,点击一个按钮后,要求获得该关键字在ie浏览器中google网页中地址栏中的地址....望各位大虾多多提供宝贵意见.........如:输入"商标",如何得到:
http://www.google.cn/search?hl=zh-CN&newwindow=1&client=aff-9991&channel=searchlink&hs=JZY&q=%E5%95%86%E6%A0%87&meta=&aq=f&oq=
这一项....

解决方案 »

  1.   

    可以参考一下这个:
    http://www.fatchow.com/blog/index.php/archives/91
      

  2.   

    这个EASY啊……URL DECODE嘛!==发代码上来。 
      

  3.   

    private void button1_Click(object sender, EventArgs e)
    {
        textBox1.Text = "http://www.google.com/search?q=" + HttpUtility.UrlEncode(textBox1.Text);
    }
    晕,刚才上不了网了。在文本框textBox1中填入你的关键字,一样的用空格分割关键字,然后点按钮。
      

  4.   

    这里还有几点需要注意的:1、地址中可能还有一些固定的内容我没有加进来的,你可以自己根据你实际的需要而添加,但上述URL地址已经可以访问到你所需要的内容。
    比如:我用IE7在Google.Cn上搜索“中国”,得到的URL是
    http://www.google.cn/search?hl=zh-CN&q=%E4%B8%AD%E5%9B%BD&meta=&aq=f&oq=
    还有:
    hl=zh-CN&  
    &meta=&aq=f&oq=
    这二段参数没有包括进来,它的意义对于搜索而言并不明显,如果你需要添加你处理一下最后的接接就可以,比如上面的代码我可以改成性这样:
    private void button1_Click(object sender, EventArgs e)
    {
        string searchTemplate = "http://www.google.cn/search?hl=zh-CN&q={0}&meta=&aq=f&oq=";
        string url = string.Format(searchTemplate, HttpUtility.UrlEncode(textBox1.Text));
        textBox2.Text = url;
        Process.Start(url);     //这里启动你的浏览器了……你可以注释掉
    }
    上面那段代码就是现在Google.Cn所使用的搜索地址。
      

  5.   

    至于你提到的
    http://www.google.cn/search?hl=zh-CN&q=%E5%95%86%E6%A0%87&meta=&aq=f&oq= 
    我不知道你的来源中这个:
    &newwindow=1&client=aff-9991&channel=searchlink&hs=JZY
    这个是如何得到的,但可以肯定的是这与搜索无关,可能是某个网站或者某个软件中附带的东西,是GOOGLE做推广用的,并非搜索所必须。
      

  6.   

    添加System.Web.dll这个程序集的引用,再在需要使用的地方引用 System.Net.Web;这个命名空间。
    这个程序集是随.NET 2.0安装的,与Web相关的程序集并不是只能在Web程序如ASP.NET中使用,你可以在任何地方使用的。
      

  7.   

    呵呵,记错了。是引用 System.Web这个命名空间,不是System.Net.Web。
      

  8.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Web;namespace UtfTransfer
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void button1_Click(object sender, EventArgs e)
            {
                this.textBox1.Text = "http://www.google.com/search?q=" + HttpUtility.UrlEncode(textBox1.Text);
            }
        }
    }
    提示错误如下:错误 1 当前上下文中不存在名称“HttpUtility” E:\VS2005\UtfTransfer\UtfTransfer\Form1.cs 21 70 UtfTransfer