Baidu: C # use Baidu to search Web pages, images, videos, etc.

Source: Internet
Author: User

You do not need to enter the Baidu homepage every time, enter keywords, and then click search. Directly create a console program and open the search page.

Click here to download all source programs

Main source program:

[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 ");
}
}
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.