我想把我获取到的HTML里的所有的所有的<a href="替换成<a href="default2.aspx?str=,但是里面有双引号,想问一下怎么用正者表达转换啊
看下面代码
1
using System;
2
using System.Data;
3
using System.Configuration;
4
using System.Collections;
5
using System.Web;
6
using System.Web.Security;
7
using System.Web.UI;
8
using System.Web.UI.WebControls;
9
using System.Web.UI.WebControls.WebParts;
10
using System.Web.UI.HtmlControls;
11
using System.Net;
12
using System.Drawing;
13
using System.Drawing.Imaging;
14
using System.IO;
15
16
17
public 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

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55
