慢速VOA的下载!
看到上次一个圆子里的弟兄提到的慢速VOA,感觉还不错,但是不想一个一个下载,所以写了段代码。
好长时间都不写代码了,手生了!
现在写代码都是为了自己用!让高手见笑了!
1
using System;
2
using System.Collections.Generic;
3
using System.ComponentModel;
4
using System.Data;
5
using System.Drawing;
6
using System.Text;
7
using System.Windows.Forms;
8
using System.Net;
9
using System.IO;
10
using System.Text.RegularExpressions;
11![](/Images/OutliningIndicators/None.gif)
12
namespace VOA
13
{
14
public delegate void DelegateProgressBarPerformStep(long i);
15
public partial class Form1 : Form
16
{
17
public DelegateProgressBarPerformStep DelegateProgressBarPerformStep;
18
long iConLength;
19
public Form1()
20
{
21
InitializeComponent();
22
}
23![](/Images/OutliningIndicators/InBlock.gif)
24
public void ProgressBarPerformStep(long i)
25
{
26
this.Text = "Processing
" + string.Format("Finished: {0} / {1}", i , iConLength);
27
}
28![](/Images/OutliningIndicators/InBlock.gif)
29
private void btnGetList_Click(object sender, EventArgs e)
30
{
31
GetList(textBox1.Text);
32
}
33![](/Images/OutliningIndicators/InBlock.gif)
34
private void button1_Click(object sender, EventArgs e)
35
{
36
DownLoad(listView1.SelectedItems[0].SubItems[1].Text, listView1.SelectedItems[0].Text);
37
}
38![](/Images/OutliningIndicators/InBlock.gif)
39
private void GetList(string strUrl)
40
{
41
string strHtml = String.Empty;
42
HttpWebRequest rt = null;
43
HttpWebResponse rs = null;
44
Stream stream = null;
45
StreamReader sr = null;
46
string temp = string.Empty;
47![](/Images/OutliningIndicators/InBlock.gif)
48![](/Images/OutliningIndicators/InBlock.gif)
49
try
50
{
51
rt = (HttpWebRequest)WebRequest.Create(strUrl);
52
rs = (HttpWebResponse)rt.GetResponse();
53
stream = rs.GetResponseStream();
54
sr = new StreamReader(stream, Encoding.UTF8);
55
strHtml = sr.ReadToEnd();
56
}
57
catch (Exception ee)
58
{
59
MessageBox.Show("发生异常" + ee.Message);
60
}
61
finally
62
{
63
sr.Close();
64
stream.Close();
65
rs.Close();
66
}
67![](/Images/OutliningIndicators/InBlock.gif)
68
string regexStr = "";
69
int counter = 0;
70
int i = 0;
71
string strKey = "";
72
string strText = "";
73
try
74
{
75
regexStr = @"\<a href=.*\w{4}\-\w{2}\-\w{2}";
76
temp = "";
77
counter = 0;
78
MatchCollection mc = Regex.Matches(strHtml, regexStr);
79
counter = mc.Count;
80
for (i = 0; i < counter; ++i)
81
{
82
temp = mc[i].ToString();
83
strKey = temp.Substring(9, 13);
84
strKey = "http://bulo.hjenglish.com" + strKey;
85
int itemp = temp.IndexOf("【慢速VOA】");
86![](/Images/OutliningIndicators/InBlock.gif)
87
strText = temp.Substring(itemp);
88
listView1.Items.Add(strText);
89
listView1.Items[i].SubItems.Add(strKey);
90
}
91
mc = null;
92
}
93
catch (Exception ee)
94
{
95
MessageBox.Show(ee.Message);
96
}
97
}
98![](/Images/OutliningIndicators/InBlock.gif)
99
private void DownLoad(string strUrl, string strFile)
100
{
101
string strHtml = String.Empty;
102
HttpWebRequest rt = null;
103
HttpWebResponse rs = null;
104
Stream stream = null;
105
StreamReader sr = null;
106
string temp = string.Empty;
107![](/Images/OutliningIndicators/InBlock.gif)
108![](/Images/OutliningIndicators/InBlock.gif)
109
try
110
{
111
rt = (HttpWebRequest)WebRequest.Create(strUrl);
112
rs = (HttpWebResponse)rt.GetResponse();
113
stream = rs.GetResponseStream();
114
sr = new StreamReader(stream, Encoding.UTF8);
115
strHtml = sr.ReadToEnd();
116
}
117
catch (Exception ee)
118
{
119
MessageBox.Show("发生异常" + ee.Message);
120
}
121
finally
122
{
123
sr.Close();
124
stream.Close();
125
rs.Close();
126
}
127![](/Images/OutliningIndicators/InBlock.gif)
128
string regexStr = "";
129
int counter = 0;
130
int i = 0;
131![](/Images/OutliningIndicators/InBlock.gif)
132
GetMP3
151![](/Images/OutliningIndicators/InBlock.gif)
152
try
153
{
154
regexStr = @"参考答案:.*";
155
temp = "";
156
counter = 0;
157
MatchCollection mc = Regex.Matches(strHtml, regexStr);
158
counter = mc.Count;
159
for (i = 0; i < counter; ++i)
160
{
161
writeTxt(mc[i].ToString(),strFile);
162
}
163
mc = null;
164
}
165
catch (Exception ee)
166
{
167
MessageBox.Show(ee.Message);
168
}
169![](/Images/OutliningIndicators/InBlock.gif)
170
MessageBox.Show("下载完成");
171
}
172![](/Images/OutliningIndicators/InBlock.gif)
173
private void writeTxt(string strBody,string strFile)
174
{
175
StreamWriter sw;
176
try
177
{
178
sw = File.CreateText(strFile + ".txt");//txt文件会创建到跟目录下的BIN→Debug下
179
}
180
catch
181
{
182
Console.WriteLine("不能创建文件!");
183
return;
184
}
185![](/Images/OutliningIndicators/InBlock.gif)
186
sw.Write("{0} ",strBody);
187
sw.Close();
188![](/Images/OutliningIndicators/InBlock.gif)
189
}
190![](/Images/OutliningIndicators/InBlock.gif)
191
private void downloadMP3(string strUrl,string strFile)
192
{
193
//打开上次下载的文件或新建文件
194
long lStartPos =0;
195
System.IO.FileStream fs;
196
if (System.IO.File.Exists(strFile))
197
{
198
fs= System.IO.File.OpenWrite(strFile);
199
lStartPos=fs.Length;
200
fs.Seek(lStartPos,System.IO.SeekOrigin.Current); //移动文件流中的当前指针
201
}
202
else
203
{
204
fs = new System.IO.FileStream(strFile, System.IO.FileMode.Create);
205
lStartPos =0;
206
}
207![](/Images/OutliningIndicators/InBlock.gif)
208
long iFinished = lStartPos;
209![](/Images/OutliningIndicators/InBlock.gif)
210
//打开网络连接
211
try
212
{
213
System.Net.HttpWebRequest request =(System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(strUrl);
214![](/Images/OutliningIndicators/InBlock.gif)
215
if ( lStartPos>0)
216
request.AddRange((int)lStartPos); //设置Range值
217
218
//向服务器请求,获得服务器回应数据流
219
System.IO.Stream ns= request.GetResponse().GetResponseStream();
220
iConLength = request.GetResponse().ContentLength;
221
byte[] nbytes = new byte[512];
222
int nReadSize=0;
223
nReadSize=ns.Read(nbytes,0,512);
224
225
while( nReadSize >0)
226
{
227
iFinished += nReadSize;
228
fs.Write(nbytes,0,nReadSize);
229
nReadSize=ns.Read(nbytes,0,512);
230
//progressBar1.Invoke(this.DelegateProgressBarPerformStep, new object[] { iFinished });
231
}
232
fs.Close();
233
ns.Close();
234![](/Images/OutliningIndicators/InBlock.gif)
235
}
236
catch(Exception ex)
237
{
238
fs.Close();
239
MessageBox.Show("下载过程中出现错误:"+ex.ToString());
240
}
241
}
242
}
243
}
244![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
2
![](/Images/OutliningIndicators/None.gif)
3
![](/Images/OutliningIndicators/None.gif)
4
![](/Images/OutliningIndicators/None.gif)
5
![](/Images/OutliningIndicators/None.gif)
6
![](/Images/OutliningIndicators/None.gif)
7
![](/Images/OutliningIndicators/None.gif)
8
![](/Images/OutliningIndicators/None.gif)
9
![](/Images/OutliningIndicators/None.gif)
10
![](/Images/OutliningIndicators/None.gif)
11
![](/Images/OutliningIndicators/None.gif)
12
![](/Images/OutliningIndicators/None.gif)
13
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
14
![](/Images/OutliningIndicators/InBlock.gif)
15
![](/Images/OutliningIndicators/InBlock.gif)
16
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
17
![](/Images/OutliningIndicators/InBlock.gif)
18
![](/Images/OutliningIndicators/InBlock.gif)
19
![](/Images/OutliningIndicators/InBlock.gif)
20
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
21
![](/Images/OutliningIndicators/InBlock.gif)
22
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
23
![](/Images/OutliningIndicators/InBlock.gif)
24
![](/Images/OutliningIndicators/InBlock.gif)
25
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
26
![](/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
27
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
28
![](/Images/OutliningIndicators/InBlock.gif)
29
![](/Images/OutliningIndicators/InBlock.gif)
30
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
31
![](/Images/OutliningIndicators/InBlock.gif)
32
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
33
![](/Images/OutliningIndicators/InBlock.gif)
34
![](/Images/OutliningIndicators/InBlock.gif)
35
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
36
![](/Images/OutliningIndicators/InBlock.gif)
37
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
38
![](/Images/OutliningIndicators/InBlock.gif)
39
![](/Images/OutliningIndicators/InBlock.gif)
40
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
41
![](/Images/OutliningIndicators/InBlock.gif)
42
![](/Images/OutliningIndicators/InBlock.gif)
43
![](/Images/OutliningIndicators/InBlock.gif)
44
![](/Images/OutliningIndicators/InBlock.gif)
45
![](/Images/OutliningIndicators/InBlock.gif)
46
![](/Images/OutliningIndicators/InBlock.gif)
47
![](/Images/OutliningIndicators/InBlock.gif)
48
![](/Images/OutliningIndicators/InBlock.gif)
49
![](/Images/OutliningIndicators/InBlock.gif)
50
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
51
![](/Images/OutliningIndicators/InBlock.gif)
52
![](/Images/OutliningIndicators/InBlock.gif)
53
![](/Images/OutliningIndicators/InBlock.gif)
54
![](/Images/OutliningIndicators/InBlock.gif)
55
![](/Images/OutliningIndicators/InBlock.gif)
56
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
57
![](/Images/OutliningIndicators/InBlock.gif)
58
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
59
![](/Images/OutliningIndicators/InBlock.gif)
60
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
61
![](/Images/OutliningIndicators/InBlock.gif)
62
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
63
![](/Images/OutliningIndicators/InBlock.gif)
64
![](/Images/OutliningIndicators/InBlock.gif)
65
![](/Images/OutliningIndicators/InBlock.gif)
66
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
67
![](/Images/OutliningIndicators/InBlock.gif)
68
![](/Images/OutliningIndicators/InBlock.gif)
69
![](/Images/OutliningIndicators/InBlock.gif)
70
![](/Images/OutliningIndicators/InBlock.gif)
71
![](/Images/OutliningIndicators/InBlock.gif)
72
![](/Images/OutliningIndicators/InBlock.gif)
73
![](/Images/OutliningIndicators/InBlock.gif)
74
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
75
![](/Images/OutliningIndicators/InBlock.gif)
76
![](/Images/OutliningIndicators/InBlock.gif)
77
![](/Images/OutliningIndicators/InBlock.gif)
78
![](/Images/OutliningIndicators/InBlock.gif)
79
![](/Images/OutliningIndicators/InBlock.gif)
80
![](/Images/OutliningIndicators/InBlock.gif)
81
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
82
![](/Images/OutliningIndicators/InBlock.gif)
83
![](/Images/OutliningIndicators/InBlock.gif)
84
![](/Images/OutliningIndicators/InBlock.gif)
85
![](/Images/OutliningIndicators/InBlock.gif)
86
![](/Images/OutliningIndicators/InBlock.gif)
87
![](/Images/OutliningIndicators/InBlock.gif)
88
![](/Images/OutliningIndicators/InBlock.gif)
89
![](/Images/OutliningIndicators/InBlock.gif)
90
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
91
![](/Images/OutliningIndicators/InBlock.gif)
92
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
93
![](/Images/OutliningIndicators/InBlock.gif)
94
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
95
![](/Images/OutliningIndicators/InBlock.gif)
96
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
97
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
98
![](/Images/OutliningIndicators/InBlock.gif)
99
![](/Images/OutliningIndicators/InBlock.gif)
100
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
101
![](/Images/OutliningIndicators/InBlock.gif)
102
![](/Images/OutliningIndicators/InBlock.gif)
103
![](/Images/OutliningIndicators/InBlock.gif)
104
![](/Images/OutliningIndicators/InBlock.gif)
105
![](/Images/OutliningIndicators/InBlock.gif)
106
![](/Images/OutliningIndicators/InBlock.gif)
107
![](/Images/OutliningIndicators/InBlock.gif)
108
![](/Images/OutliningIndicators/InBlock.gif)
109
![](/Images/OutliningIndicators/InBlock.gif)
110
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
111
![](/Images/OutliningIndicators/InBlock.gif)
112
![](/Images/OutliningIndicators/InBlock.gif)
113
![](/Images/OutliningIndicators/InBlock.gif)
114
![](/Images/OutliningIndicators/InBlock.gif)
115
![](/Images/OutliningIndicators/InBlock.gif)
116
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
117
![](/Images/OutliningIndicators/InBlock.gif)
118
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
119
![](/Images/OutliningIndicators/InBlock.gif)
120
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
121
![](/Images/OutliningIndicators/InBlock.gif)
122
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
123
![](/Images/OutliningIndicators/InBlock.gif)
124
![](/Images/OutliningIndicators/InBlock.gif)
125
![](/Images/OutliningIndicators/InBlock.gif)
126
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
127
![](/Images/OutliningIndicators/InBlock.gif)
128
![](/Images/OutliningIndicators/InBlock.gif)
129
![](/Images/OutliningIndicators/InBlock.gif)
130
![](/Images/OutliningIndicators/InBlock.gif)
131
![](/Images/OutliningIndicators/InBlock.gif)
132
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
151
![](/Images/OutliningIndicators/InBlock.gif)
152
![](/Images/OutliningIndicators/InBlock.gif)
153
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
154
![](/Images/OutliningIndicators/InBlock.gif)
155
![](/Images/OutliningIndicators/InBlock.gif)
156
![](/Images/OutliningIndicators/InBlock.gif)
157
![](/Images/OutliningIndicators/InBlock.gif)
158
![](/Images/OutliningIndicators/InBlock.gif)
159
![](/Images/OutliningIndicators/InBlock.gif)
160
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
161
![](/Images/OutliningIndicators/InBlock.gif)
162
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
163
![](/Images/OutliningIndicators/InBlock.gif)
164
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
165
![](/Images/OutliningIndicators/InBlock.gif)
166
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
167
![](/Images/OutliningIndicators/InBlock.gif)
168
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
169
![](/Images/OutliningIndicators/InBlock.gif)
170
![](/Images/OutliningIndicators/InBlock.gif)
171
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
172
![](/Images/OutliningIndicators/InBlock.gif)
173
![](/Images/OutliningIndicators/InBlock.gif)
174
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
175
![](/Images/OutliningIndicators/InBlock.gif)
176
![](/Images/OutliningIndicators/InBlock.gif)
177
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
178
![](/Images/OutliningIndicators/InBlock.gif)
179
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
180
![](/Images/OutliningIndicators/InBlock.gif)
181
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
182
![](/Images/OutliningIndicators/InBlock.gif)
183
![](/Images/OutliningIndicators/InBlock.gif)
184
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
185
![](/Images/OutliningIndicators/InBlock.gif)
186
![](/Images/OutliningIndicators/InBlock.gif)
187
![](/Images/OutliningIndicators/InBlock.gif)
188
![](/Images/OutliningIndicators/InBlock.gif)
189
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
190
![](/Images/OutliningIndicators/InBlock.gif)
191
![](/Images/OutliningIndicators/InBlock.gif)
192
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
193
![](/Images/OutliningIndicators/InBlock.gif)
194
![](/Images/OutliningIndicators/InBlock.gif)
195
![](/Images/OutliningIndicators/InBlock.gif)
196
![](/Images/OutliningIndicators/InBlock.gif)
197
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
198
![](/Images/OutliningIndicators/InBlock.gif)
199
![](/Images/OutliningIndicators/InBlock.gif)
200
![](/Images/OutliningIndicators/InBlock.gif)
201
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
202
![](/Images/OutliningIndicators/InBlock.gif)
203
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
204
![](/Images/OutliningIndicators/InBlock.gif)
205
![](/Images/OutliningIndicators/InBlock.gif)
206
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
207
![](/Images/OutliningIndicators/InBlock.gif)
208
![](/Images/OutliningIndicators/InBlock.gif)
209
![](/Images/OutliningIndicators/InBlock.gif)
210
![](/Images/OutliningIndicators/InBlock.gif)
211
![](/Images/OutliningIndicators/InBlock.gif)
212
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
213
![](/Images/OutliningIndicators/InBlock.gif)
214
![](/Images/OutliningIndicators/InBlock.gif)
215
![](/Images/OutliningIndicators/InBlock.gif)
216
![](/Images/OutliningIndicators/InBlock.gif)
217
![](/Images/OutliningIndicators/InBlock.gif)
218
![](/Images/OutliningIndicators/InBlock.gif)
219
![](/Images/OutliningIndicators/InBlock.gif)
220
![](/Images/OutliningIndicators/InBlock.gif)
221
![](/Images/OutliningIndicators/InBlock.gif)
222
![](/Images/OutliningIndicators/InBlock.gif)
223
![](/Images/OutliningIndicators/InBlock.gif)
224
![](/Images/OutliningIndicators/InBlock.gif)
225
![](/Images/OutliningIndicators/InBlock.gif)
226
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
227
![](/Images/OutliningIndicators/InBlock.gif)
228
![](/Images/OutliningIndicators/InBlock.gif)
229
![](/Images/OutliningIndicators/InBlock.gif)
230
![](/Images/OutliningIndicators/InBlock.gif)
231
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
232
![](/Images/OutliningIndicators/InBlock.gif)
233
![](/Images/OutliningIndicators/InBlock.gif)
234
![](/Images/OutliningIndicators/InBlock.gif)
235
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
236
![](/Images/OutliningIndicators/InBlock.gif)
237
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
238
![](/Images/OutliningIndicators/InBlock.gif)
239
![](/Images/OutliningIndicators/InBlock.gif)
240
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
241
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
242
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
243
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
244
![](/Images/OutliningIndicators/None.gif)