我們可以不用每次都先進入百度主頁,然後輸入關鍵詞,然後點擊搜索。直接做一個控制台程序,打開搜索頁面就OK了。
點擊此處下載全部源程序
主要源程序:
[csharp]
// Author: PJ
using System;
using System.Web;
using System.Diagnostics;
namespace QhCSharp{
class Program{
public static void Main(string[] args){
if( args.Length == 0 ){
Process.Start("http://www.baidu.com");
}else if( args.Length == 1 ){
Process.Start("http://www.baidu.com/s?wd=" + args[0]);
}else if( args.Length == 2 ){
string searchType = args[0].ToLower();
if( searchType == "news" ){
Process.Start("http://news.baidu.com/ns?word=" + HttpUtility.UrlEncode(args[1],System.Text.Encoding.GetEncoding("GB2312")));
}else if( searchType == "web" ){
Process.Start("http://www.baidu.com/s?wd=" + HttpUtility.UrlEncode(args[1],System.Text.Encoding.GetEncoding("GB2312")));
}else if( searchType == "mp3" ){
Process.Start("http://mp3.baidu.com/m?word=" + HttpUtility.UrlEncode(args[1],System.Text.Encoding.GetEncoding("GB2312")));
}else if( searchType == "image" ){
Process.Start("http://image.baidu.com/i?word=" + HttpUtility.UrlEncode(args[1],System.Text.Encoding.GetEncoding("GB2312")));
}else if( searchType == "video" ){
Process.Start("http://video.baidu.com/v?word=" + HttpUtility.UrlEncode(args[1],System.Text.Encoding.GetEncoding("GB2312")));
}else if( searchType == "wenku" ){
Process.Start("http://wenku.baidu.com/search?word=" + HttpUtility.UrlEncode(args[1],System.Text.Encoding.GetEncoding("GB2312")));
}else{
Console.WriteLine("Unknown search type.");
}
}else{
Console.WriteLine("Usage: Baidu <SearchType> <Keyword>");
Console.WriteLine("SearchType:");
Console.WriteLine("\tnews");
Console.WriteLine("\tweb");
Console.WriteLine("\tmp3");
Console.WriteLine("\timage");
Console.WriteLine("\tvideo");
Console.WriteLine("\twenku");
}
}
}
}