单击按钮触发以下代码 GetRemoteObj o = new GetRemoteObj();
string Url = this.TextBox1.Text;
string HtmlCode = o.GetRemoteHtmlCode(Url);
Byte[] gb1 = System.Text.Encoding.GetEncoding("gb2312").GetBytes(HtmlCode);
HtmlCode = System.Text.Encoding.UTF8.GetString(gb1);
HtmlCode = HtmlCode.Replace("utf-8", "gb2312");
try
{
string FileName = "123.htm";
string ffname = System.Web.HttpContext.Current.Server.MapPath("../") + FileName;
File.Delete(ffname);
string txthtm = HtmlCode;
//创建文件信息对象
FileInfo finfo = new FileInfo(ffname);
//以打开或者写入的形式创建文件流
using (FileStream fs = finfo.OpenWrite())
{
//根据上面创建的文件流创建写数据流
StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.GetEncoding("gb2312"));
//StreamWriter sw = new StreamWriter(System.Web.HttpContext.Current.Server.MapPath(Saveadd) + FileName, false, System.Text.Encoding.GetEncoding(EncodingCode));
//把新的内容写到创建的HTML页面中
//sw.WriteLine(txthtm);
sw.WriteLine(txthtm);
sw.Flush();
sw.Close(); }
}
catch (Exception ex)
{
}
//获取标题
string Html = o.GetRemoteHtmlCode("http://192.168.1.2:146/123.htm");
string Reg = "<title>.+?</title>";
string GetValue = o.GetRegValue(Reg, Html);
string title = o.RegReplace(GetValue, "<title>", "</title>");
this.Label1.Text = "新闻标题是:" + title;
//获取新闻内容
Html = Html.Substring(Html.IndexOf("<!--资讯正文-->"), (Html.IndexOf("<h2>相关新闻</h2>") - Html.IndexOf("<!--资讯正文-->")));
this.Label2.Text = "新闻内容是:" + Html; o.Dispose();步骤是把新闻页抓下来,转换成gb2312编码,写到本地123.htm文件里,然后再截取123.htm的标题和新闻正文,结果大部分是gb2312码,但多了很多?号
string Url = this.TextBox1.Text;
string HtmlCode = o.GetRemoteHtmlCode(Url);
Byte[] gb1 = System.Text.Encoding.GetEncoding("gb2312").GetBytes(HtmlCode);
HtmlCode = System.Text.Encoding.UTF8.GetString(gb1);
HtmlCode = HtmlCode.Replace("utf-8", "gb2312");
try
{
string FileName = "123.htm";
string ffname = System.Web.HttpContext.Current.Server.MapPath("../") + FileName;
File.Delete(ffname);
string txthtm = HtmlCode;
//创建文件信息对象
FileInfo finfo = new FileInfo(ffname);
//以打开或者写入的形式创建文件流
using (FileStream fs = finfo.OpenWrite())
{
//根据上面创建的文件流创建写数据流
StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.GetEncoding("gb2312"));
//StreamWriter sw = new StreamWriter(System.Web.HttpContext.Current.Server.MapPath(Saveadd) + FileName, false, System.Text.Encoding.GetEncoding(EncodingCode));
//把新的内容写到创建的HTML页面中
//sw.WriteLine(txthtm);
sw.WriteLine(txthtm);
sw.Flush();
sw.Close(); }
}
catch (Exception ex)
{
}
//获取标题
string Html = o.GetRemoteHtmlCode("http://192.168.1.2:146/123.htm");
string Reg = "<title>.+?</title>";
string GetValue = o.GetRegValue(Reg, Html);
string title = o.RegReplace(GetValue, "<title>", "</title>");
this.Label1.Text = "新闻标题是:" + title;
//获取新闻内容
Html = Html.Substring(Html.IndexOf("<!--资讯正文-->"), (Html.IndexOf("<h2>相关新闻</h2>") - Html.IndexOf("<!--资讯正文-->")));
this.Label2.Text = "新闻内容是:" + Html; o.Dispose();步骤是把新闻页抓下来,转换成gb2312编码,写到本地123.htm文件里,然后再截取123.htm的标题和新闻正文,结果大部分是gb2312码,但多了很多?号
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货