mycmd系列,抓GOOGLE的翻译做自己的翻译
是一个Console的app
使用方法 :把Translate.exe放到system32的文件夹中,打开cmd,输入Translate空格hello ,就可以查到hello在google上的解释。
如果不放在system32中就要自己设定系统环境变量Path
使用的是.net4.0。
源码:
1 using System.Net;
2 using System.IO;
3 using System.Text;
4 using System;
5
6 namespace Translate
7 {
8 class Program
9 {
10 static void Main(string[] args)
11 {
12 HttpWebRequest webrequest = HttpWebRequest.Create(@"http://www.google.com.hk/search?hl=zh-CN&q=fy%20"+args[0]) as HttpWebRequest;
13 webrequest.CookieContainer = new CookieContainer();
14 HttpWebResponse webresponse = webrequest.GetResponse() as HttpWebResponse;
15 using (Stream strM = webresponse.GetResponseStream())
16 {
17 using (StreamReader sr = new StreamReader(strM, Encoding.GetEncoding("gb2312")))
18 {
19 Console.WriteLine(sr.ReadToEnd().Filter());
20 }
21 }
22
23 }
24
25 }
26 public static class HtmlExtern
27 {
28 /// <summary>
29 /// author:Snowleung
30 /// </summary>
31 /// <param name="TempContent"></param>
32 /// <returns></returns>
33 public static string Filter(this string TempContent)
34 {
35 string x=TempContent.regularExpressionsOfHTML();
36 int start = x.IndexOf("您想要的语言");
37 int last = x.IndexOf("translate");
38 return x.Substring(start, last - start);
39 }
40 /// <summary>
41 /// This method from :http://www.cnblogs.com/yuanjw/archive/2007/05/23/756724.html
42 /// </summary>
43 /// <param name="TempContent"></param>
44 /// <returns></returns>
45 public static string regularExpressionsOfHTML(this string TempContent)
46 {
47 //TempContent = System.Text.RegularExpressions.Regex.Replace(TempContent,"<[^>]+>",""); //任意多个
48 TempContent = System.Text.RegularExpressions.Regex.Replace(TempContent, "<[^>]*>", ""); //匹配一个
49 return TempContent;
50 }
51 }
2 using System.IO;
3 using System.Text;
4 using System;
5
6 namespace Translate
7 {
8 class Program
9 {
10 static void Main(string[] args)
11 {
12 HttpWebRequest webrequest = HttpWebRequest.Create(@"http://www.google.com.hk/search?hl=zh-CN&q=fy%20"+args[0]) as HttpWebRequest;
13 webrequest.CookieContainer = new CookieContainer();
14 HttpWebResponse webresponse = webrequest.GetResponse() as HttpWebResponse;
15 using (Stream strM = webresponse.GetResponseStream())
16 {
17 using (StreamReader sr = new StreamReader(strM, Encoding.GetEncoding("gb2312")))
18 {
19 Console.WriteLine(sr.ReadToEnd().Filter());
20 }
21 }
22
23 }
24
25 }
26 public static class HtmlExtern
27 {
28 /// <summary>
29 /// author:Snowleung
30 /// </summary>
31 /// <param name="TempContent"></param>
32 /// <returns></returns>
33 public static string Filter(this string TempContent)
34 {
35 string x=TempContent.regularExpressionsOfHTML();
36 int start = x.IndexOf("您想要的语言");
37 int last = x.IndexOf("translate");
38 return x.Substring(start, last - start);
39 }
40 /// <summary>
41 /// This method from :http://www.cnblogs.com/yuanjw/archive/2007/05/23/756724.html
42 /// </summary>
43 /// <param name="TempContent"></param>
44 /// <returns></returns>
45 public static string regularExpressionsOfHTML(this string TempContent)
46 {
47 //TempContent = System.Text.RegularExpressions.Regex.Replace(TempContent,"<[^>]+>",""); //任意多个
48 TempContent = System.Text.RegularExpressions.Regex.Replace(TempContent, "<[^>]*>", ""); //匹配一个
49 return TempContent;
50 }
51 }
52 }
附上Solution:(vs2010)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?