1 //从网页中读取结果数,返回搜索结果数
2 public string ReturnCount(stringkeyword,stringinfoclass)
3 {
4 try
5 {
6 string keyWord = this.GB2Unicode(keyword);
7 string infoClass = this.GB2Unicode(infoclass);
8 string mmmm = "";
9 string url = "http://www.search.hc360.com/cgi-bin/getcount?w=" + keyWord + "&c=" + infoClass + "&b=&s=&i=";
10
11 WebRequest wreq = WebRequest.Create(url);
12 HttpWebResponse wresp = (HttpWebResponse)wreq.GetResponse();
13 Stream s = wresp.GetResponseStream();
14 StreamReader sr = new StreamReader(s, System.Text.Encoding.GetEncoding("gb2312"));
15 string temp = sr.ReadToEnd();
16 //Response.Write(temp);
17 string[] str = temp.Split(';');
18 if (str[0] != null)
19 {
20 //HttpContext.Current.Response.Write(str[0].ToString());
21 //Response.Write(str[0].Split(']')[0].Split('[')[1].ToString());
22 mmmm += str[0].Split(']')[1].Split('=')[1].ToString();
23 }
24 else
25 {
26 mmmm += "134";
27 }
28 return mmmm;
29 }
30 catch
31 {
32 return "100";
33 }
34
35 }
36
37
38 //因为streamreader不支持中文,所以要通过这个方法,把中文转换成其支持的代码
39 public string GB2Unicode(string strSearch)
40 {
41 string Hexs = "";
42 string HH;
43 Encoding GB = Encoding.GetEncoding("GB2312");
44 Encoding unicode = Encoding.Unicode;
45
46 byte[] GBBytes = GB.GetBytes(strSearch);
47 for (int i = 0; i < GBBytes.Length; i++)
48 {
49 HH = "%" + GBBytes[i].ToString("x");
50 Hexs += HH;
51 }
52 return Hexs;
53 }
54
2 public string ReturnCount(stringkeyword,stringinfoclass)
3 {
4 try
5 {
6 string keyWord = this.GB2Unicode(keyword);
7 string infoClass = this.GB2Unicode(infoclass);
8 string mmmm = "";
9 string url = "http://www.search.hc360.com/cgi-bin/getcount?w=" + keyWord + "&c=" + infoClass + "&b=&s=&i=";
10
11 WebRequest wreq = WebRequest.Create(url);
12 HttpWebResponse wresp = (HttpWebResponse)wreq.GetResponse();
13 Stream s = wresp.GetResponseStream();
14 StreamReader sr = new StreamReader(s, System.Text.Encoding.GetEncoding("gb2312"));
15 string temp = sr.ReadToEnd();
16 //Response.Write(temp);
17 string[] str = temp.Split(';');
18 if (str[0] != null)
19 {
20 //HttpContext.Current.Response.Write(str[0].ToString());
21 //Response.Write(str[0].Split(']')[0].Split('[')[1].ToString());
22 mmmm += str[0].Split(']')[1].Split('=')[1].ToString();
23 }
24 else
25 {
26 mmmm += "134";
27 }
28 return mmmm;
29 }
30 catch
31 {
32 return "100";
33 }
34
35 }
36
37
38 //因为streamreader不支持中文,所以要通过这个方法,把中文转换成其支持的代码
39 public string GB2Unicode(string strSearch)
40 {
41 string Hexs = "";
42 string HH;
43 Encoding GB = Encoding.GetEncoding("GB2312");
44 Encoding unicode = Encoding.Unicode;
45
46 byte[] GBBytes = GB.GetBytes(strSearch);
47 for (int i = 0; i < GBBytes.Length; i++)
48 {
49 HH = "%" + GBBytes[i].ToString("x");
50 Hexs += HH;
51 }
52 return Hexs;
53 }
54