Baidu:C#利用百度来搜索网页、图片、视频等等
我们可以不用每次都先进入百度主页,然后输入关键词,然后点击搜索。直接做一个控制台程序,打开搜索页面就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");
}
}
}
}
补充:软件开发 , C# ,