You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

242 lines
9.7 KiB
C#

10 months ago
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
namespace DSWeb.WebSearchEngine
{
public partial class SearchEngineAdapter : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
WebClient webClient = new WebClient();
Byte[] pageHtmlBtyes;
string strUrl = "http://www.qingdaoport.net/ywzx/qqct/dpcx/hgfx.jsp?val=COSU6066673580";
//http://www.qingdaoport.net/ywzx/qqct/dpcx/ydbg.jsp?tdh=COSU6066673580
/*
sldata[10]:=twsou('<td align="center">','</td>',sl[i]);
if not aQuery2.Locate('',trim(sldata[5]),[]) then begin
aQuery2.Insert;
aQuery2.fieldbyname('').AsString:=bsno;
aQuery2.FieldByName('').AsString:=sldata[1];
aQuery2.FieldByName('').AsString:=sldata[2];
aQuery2.FieldByName('').AsString:=sldata[3];
aQuery2.FieldByName('').AsString:=sldata[4];
aQuery2.FieldByName('').AsString:=sldata[5];
aQuery2.FieldByName('').AsString:=sldata[6];
aQuery2.FieldByName('').AsString:=sldata[7];
aQuery2.FieldByName('').AsString:=sldata[8];
aQuery2.FieldByName('').AsString:=sldata[9];
aQuery2.FieldByName('').AsString:=sldata[10];
aQuery2.FieldByName('').AsString:='QQCT';
*/
//http://www.qingdaoport.net/ywzx/qqct/dpcx/hgfx.jsp?val=COSU6066673580
/*
if not aQuery2.Locate('',trim(sldata[1]),[]) then begin
aQuery2.Insert;
aQuery2.fieldbyname('').AsString:=bsno;
aQuery2.FieldByName('').AsString:=sldata[1];
aQuery2.FieldByName('').AsString:=sldata[2];
aQuery2.FieldByName('').Asinteger:=strtointdef(sldata[3],0);
aQuery2.FieldByName('').AsString:=sldata[4];
aQuery2.FieldByName('').AsString:=sldata[5];
aQuery2.FieldByName('').AsString:=sldata[6];
aQuery2.FieldByName('').Asfloat:=strtofloatdef(sldata[7],0);
aQuery2.FieldByName('').Asfloat:=strtofloatdef(sldata[8],0);
aQuery2.FieldByName('').AsString:=sldata[9];
aQuery2.FieldByName('').AsString:=sldata[10];
aQuery2.FieldByName('').AsString:='QQCT';*/
//http://www.qingdaoport.net/ywzx/qqctu/customs_arrschema.jsp?tdh=APLU063457596
/* if not aQuery2.Locate('',trim(sldata[5]),[]) then begin
aQuery2.Insert;
aQuery2.fieldbyname('').AsString:=bsno;
aQuery2.FieldByName('').AsString:=sldata[1];
aQuery2.FieldByName('').AsString:=sldata[2];
aQuery2.FieldByName('').AsString:=sldata[3];
aQuery2.FieldByName('').AsString:=sldata[4];
aQuery2.FieldByName('').AsString:=sldata[5];
aQuery2.FieldByName('').AsString:=sldata[6];
aQuery2.FieldByName('').AsString:=sldata[7];
aQuery2.FieldByName('').AsString:=sldata[8];
aQuery2.FieldByName('').AsString:=sldata[9];
aQuery2.FieldByName('').AsString:=sldata[10];
aQuery2.FieldByName('').AsString:='QQCTU';*/
//http://www.qingdaoport.net/ywzx/qqctu/customs_release.jsp?val=APLU063457596
/* if not aQuery2.Locate('',trim(sldata[1]),[]) then begin
aQuery2.Insert;
aQuery2.fieldbyname('').AsString:=bsno;
aQuery2.FieldByName('').AsString:=sldata[1];
aQuery2.FieldByName('').AsString:=sldata[2];
aQuery2.FieldByName('').Asinteger:=strtointdef(sldata[3],0);
aQuery2.FieldByName('').AsString:=sldata[4];
aQuery2.FieldByName('').AsString:=sldata[5];
aQuery2.FieldByName('').AsString:=sldata[6];
aQuery2.FieldByName('').Asfloat:=strtofloatdef(sldata[7],0);
aQuery2.FieldByName('').Asfloat:=strtofloatdef(sldata[8],0);
aQuery2.FieldByName('').AsString:=sldata[9];
aQuery2.FieldByName('').AsString:=sldata[10];
aQuery2.FieldByName('').AsString:='QQCTU';*/
pageHtmlBtyes = webClient.DownloadData(strUrl);
//UTF8Encoding utf8Encoding = new UTF8Encoding();
Encoding gbEncoding = Encoding.GetEncoding("gb2312");
this.txt_val.Value = gbEncoding.GetString(pageHtmlBtyes);
//
ArrayList alist = new ArrayList();
string[] txtval = gbEncoding.GetString(pageHtmlBtyes).Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
string ls = "";
for (int i = 0; i < txtval.Length; i++)
{
ls = txtval[i].ToString().Trim().Replace("\t", "");
int sss = ls.IndexOf(">")+1;
int ttt = 0;
if (sss > 0)
{
if (ls.Substring(0, sss).Equals("<td height=\"24\" align=\"center\">"))
{
ls = ls.Substring(sss);
ttt=ls.IndexOf("<");
if (ttt > 0)
{
ls = ls.Substring(0, ttt);
}
else
{
ls = "";
}
alist.Add(ls);
}
else if (ls.Substring(0, sss).Equals("<td align=\"center\" bgcolor=\"#EFF2FF\">"))
{
ls = ls.Substring(sss);
ttt = ls.IndexOf("<");
if (ttt > 0)
{
ls = ls.Substring(0, ttt);
}
else
{
ls = "";
}
alist.Add(ls);
}
else if (ls.Substring(0, sss).Equals("<td height=\"20\" align=\"center\">"))
{
ls = ls.Substring(sss);
ttt = ls.IndexOf("<");
if (ttt > 0)
{
ls = ls.Substring(0, ttt);
}
else
{
ls = "";
}
alist.Add(ls);
}
else if (ls.Substring(0, sss).Equals("<td align=\"center\">"))
{
ls = ls.Substring(sss);
ttt = ls.IndexOf("<");
if (ttt > 0)
{
ls = ls.Substring(0, ttt);
}
else
{
ls = "";
}
alist.Add(ls);
}
}
}
//-------
this.txt_val.Value = "";
for (int i = 0; i < alist.Count; i++)
{
this.txt_val.Value += alist[i].ToString().Trim() + "\r\n";
}
}
#region Unicode-GB Code转换
/// <summary>
/// Unicode-GB Code转换
/// </summary>
/// <param name="text">将Unicode编码字符转换成GB编码字符</param>
/// <returns>GB Code字符串</returns>
public string UnicodeToGB(string text)
{
UnicodeEncoding unicode = new UnicodeEncoding();
text = unicode.GetString(unicode.GetBytes(Regex.Unescape(text.Trim())));
return text;
}
/// <summary>
/// Unicode-GB Code转换
/// </summary>
/// <param name="text">将Unicode编码字符转换成GB编码字符</param>
/// <returns>GB Code字符串</returns>
public string UnicodeToGB_Old(string text)
{
MatchCollection mc = Regex.Matches(text, "([\\w]+)|(\\\\u([\\w]{4}))");
if (mc != null && mc.Count > 0)
{
StringBuilder sb = new StringBuilder();
foreach (Match m2 in mc)
{
string v = m2.Value;
if (v.IndexOf("\\") >= 0)
{
string word = v.Substring(2);
byte[] codes = new byte[2];
int code = Convert.ToInt32(word.Substring(0, 2), 16);
int code2 = Convert.ToInt32(word.Substring(2), 16);
codes[0] = (byte)code2;
codes[1] = (byte)code;
sb.Append(Encoding.Unicode.GetString(codes));
}
else
{
sb.Append(v);
}
}
return sb.ToString();
}
else
{
return text;
}
}
#endregion
}
}