赞
踩
- public static void webrequestGetdata(string dataurl) {
-
- string data = string.Empty;
- if (string.IsNullOrEmpty(dataurl))
- {
- dataurl = @"https://book.douban.com/";
- //创建发送请求
- WebRequest webrequest = WebRequest.Create(dataurl);
- //设置请求方式
- webrequest.Method = "get";
- //发送请求并返回响应
- WebResponse webresponse = webrequest.GetResponse();
- //将数据转换成流
- using (StreamReader sr = new StreamReader(webresponse.GetResponseStream()))
- {
- //将流转换成字符串
- data = data + sr.ReadToEnd();
- }
- // string regex = "^href=('|\"){1}(http|https){1}:(\\\\|//){1}.+('|\"){1}$";
- string regex = "href=('|\"){1}[^\"']+('|\"){1}";
- Regex re = new Regex(regex);
- MatchCollection matchlist = re.Matches(data);
- string filedata = string.Empty;
- foreach (Match item in matchlist)
- {
- Console.WriteLine(item.Value);
- filedata += item.Value + '\n';
- }
- File.WriteAllText(@"C:\Users\Administrator\Desktop\1.txt", filedata);
-
- }
- else
- {
- data = "";
- }
-
-
- // Console.WriteLine(data);
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。