我想把我获取到的HTML里的所有的所有的<a href="替换成<a href="default2.aspx?str=,但是里面有双引号,想问一下怎么用正者表达转换啊
看下面代码
1using System;
2using System.Data;
3using System.Configuration;
4using System.Collections;
5using System.Web;
6using System.Web.Security;
7using System.Web.UI;
8using System.Web.UI.WebControls;
9using System.Web.UI.WebControls.WebParts;
10using System.Web.UI.HtmlControls;
11using System.Net;
12using System.Drawing;
13using System.Drawing.Imaging;
14using System.IO;
15
16
17public partial class Default2 : System.Web.UI.Page
18{
19 protected void Page_Load(object sender, EventArgs e)
20 {
21 GetWeather();
22 }
23 private void GetWeather()
24 {
25 string str = "http://z.zhongsou.com/gn.htm";
26 try
27 {
28 str = Request.Params["str"].ToString();
29
30 }
31 catch
32 {
33
34 }
35 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(str);
36 request.Method = "Get";
37 request.ContentType = "application/x-www-form-urlencoded";
38 WebResponse response = request.GetResponse();
39 Stream s = response.GetResponseStream();
40 StreamReader sr = new StreamReader(s, System.Text.Encoding.GetEncoding("GB2312"));
41 string html = sr.ReadToEnd();
42 s.Close();
43 sr.Close();
44 string htm = html.Replace("<a href=", "<a href='default2.aspx?str=");//我想把我获取到的HTML里的所有的所有的<a href="替换成<a href="default2.aspx?str=,但是里面有双引号,想问一下怎么用正者表达转换啊
45 System.IO.StreamWriter sw;
46 string name = System.DateTime.Now.Date.ToShortDateString()+ System.DateTime.Now.Year.ToString() + System.DateTime.Now.Second.ToString();
47 sw = new System.IO.StreamWriter(Server.MapPath(name + ".htm"), false, System.Text.Encoding.GetEncoding("GB2312"));
48 sw.Write(htm);
49 sw.Close();
50 // Response.Write(html);
51 Response.Write(html);
52
53 }
54}
55
2using System.Data;
3using System.Configuration;
4using System.Collections;
5using System.Web;
6using System.Web.Security;
7using System.Web.UI;
8using System.Web.UI.WebControls;
9using System.Web.UI.WebControls.WebParts;
10using System.Web.UI.HtmlControls;
11using System.Net;
12using System.Drawing;
13using System.Drawing.Imaging;
14using System.IO;
15
16
17public partial class Default2 : System.Web.UI.Page
18{
19 protected void Page_Load(object sender, EventArgs e)
20 {
21 GetWeather();
22 }
23 private void GetWeather()
24 {
25 string str = "http://z.zhongsou.com/gn.htm";
26 try
27 {
28 str = Request.Params["str"].ToString();
29
30 }
31 catch
32 {
33
34 }
35 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(str);
36 request.Method = "Get";
37 request.ContentType = "application/x-www-form-urlencoded";
38 WebResponse response = request.GetResponse();
39 Stream s = response.GetResponseStream();
40 StreamReader sr = new StreamReader(s, System.Text.Encoding.GetEncoding("GB2312"));
41 string html = sr.ReadToEnd();
42 s.Close();
43 sr.Close();
44 string htm = html.Replace("<a href=", "<a href='default2.aspx?str=");//我想把我获取到的HTML里的所有的所有的<a href="替换成<a href="default2.aspx?str=,但是里面有双引号,想问一下怎么用正者表达转换啊
45 System.IO.StreamWriter sw;
46 string name = System.DateTime.Now.Date.ToShortDateString()+ System.DateTime.Now.Year.ToString() + System.DateTime.Now.Second.ToString();
47 sw = new System.IO.StreamWriter(Server.MapPath(name + ".htm"), false, System.Text.Encoding.GetEncoding("GB2312"));
48 sw.Write(htm);
49 sw.Close();
50 // Response.Write(html);
51 Response.Write(html);
52
53 }
54}
55