怎么获取别人网站的数据?
答案:3 悬赏:60 手机版
解决时间 2021-03-16 22:12
- 提问者网友:孤山下
- 2021-03-16 17:14
怎么获取别人网站的数据?
最佳答案
- 五星知识达人网友:你哪知我潦倒为你
- 2021-03-16 17:31
给你一段代码。可以参照!
///
/// 获取开奖号码
///
///
public string GetNum(string Issue)
{
string number = "";
string url = "请填写你要抓取的地址";
string rl = null;
try
{
System.Net.WebRequest webRequest = System.Net.WebRequest.Create(url);
System.Net.WebResponse Response = webRequest.GetResponse();
Stream resStream = Response.GetResponseStream();
StreamReader sr = new StreamReader(resStream, Encoding.GetEncoding("GB2312"));
StringBuilder sb = new StringBuilder();
while ((rl = sr.ReadLine()) != null)
{
sb.Append(rl);
}
sr.Close();
resStream.Close();
string str = sb.ToString();
Regex rgLink = new Regex(@"<\s*link[^>]*([^<]|<(?!link))*/>", RegexOptions.IgnoreCase);
MatchCollection mcLink = rgLink.Matches(str);
foreach (Match matchLink in mcLink)
{
str = str.Replace(matchLink.Value, "");
}
Regex rgNum = new Regex(@"<\s*li[^>]*>([^<]|<(?!/li))*<\s*/li\s*>", RegexOptions.IgnoreCase);
MatchCollection mc = rgNum.Matches(str);
List list = new List();
Regex rgFind = new Regex(@"[0-9]{2}", RegexOptions.IgnoreCase);
foreach (Match match in mc)
{
string temp = match.Value;
Match m = rgFind.Match(temp);
list.Add(m.Value.Trim());
}
foreach (string v in list)
{
number += v;
}
return number;
}
catch (Exception)
{
return "False";
}
}
///
/// 获取开奖号码
///
///
public string GetNum(string Issue)
{
string number = "";
string url = "请填写你要抓取的地址";
string rl = null;
try
{
System.Net.WebRequest webRequest = System.Net.WebRequest.Create(url);
System.Net.WebResponse Response = webRequest.GetResponse();
Stream resStream = Response.GetResponseStream();
StreamReader sr = new StreamReader(resStream, Encoding.GetEncoding("GB2312"));
StringBuilder sb = new StringBuilder();
while ((rl = sr.ReadLine()) != null)
{
sb.Append(rl);
}
sr.Close();
resStream.Close();
string str = sb.ToString();
Regex rgLink = new Regex(@"<\s*link[^>]*([^<]|<(?!link))*/>", RegexOptions.IgnoreCase);
MatchCollection mcLink = rgLink.Matches(str);
foreach (Match matchLink in mcLink)
{
str = str.Replace(matchLink.Value, "");
}
Regex rgNum = new Regex(@"<\s*li[^>]*>([^<]|<(?!/li))*<\s*/li\s*>", RegexOptions.IgnoreCase);
MatchCollection mc = rgNum.Matches(str);
List
Regex rgFind = new Regex(@"[0-9]{2}", RegexOptions.IgnoreCase);
foreach (Match match in mc)
{
string temp = match.Value;
Match m = rgFind.Match(temp);
list.Add(m.Value.Trim());
}
foreach (string v in list)
{
number += v;
}
return number;
}
catch (Exception)
{
return "False";
}
}
全部回答
- 1楼网友:有你哪都是故乡
- 2021-03-16 19:08
问题不清楚,举个例子出来或许明白点
- 2楼网友:纵马山川剑自提
- 2021-03-16 17:52
为什么
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯