程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> Baidu:C#利用百度來搜索網頁、圖片、視頻等等

Baidu:C#利用百度來搜索網頁、圖片、視頻等等

編輯: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"); 
            } 
        } 
    } 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved