Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从网站获取数据_C#_Windows Phone 8 - Fatal编程技术网

C# 从网站获取数据

C# 从网站获取数据,c#,windows-phone-8,C#,Windows Phone 8,我从网站上获取数据,但我没有得到网站的主体部分 我刚拿到冠军 这是我的密码 public void getpage() { Uri u = new Uri("http://www.vaktija.ba/mobile/"); WebClient client = new WebClient(); client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(DownloadStringC

我从网站上获取数据,但我没有得到网站的主体部分 我刚拿到冠军

这是我的密码

public void getpage() {
    Uri u = new Uri("http://www.vaktija.ba/mobile/");
    WebClient client = new WebClient();

    client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(DownloadStringCallback2);
     client.DownloadStringAsync(u);
}

private void DownloadStringCallback2(object sender, DownloadStringCompletedEventArgs e) {
     //data.Text = e.Result;
     data.Text = Regex.Replace(e.Result, "<[^>]*>", "");
}

private void but_Click(object sender, RoutedEventArgs e) {
    getpage();
}
public void getpage(){
Uri u=新的Uri(“http://www.vaktija.ba/mobile/");
WebClient客户端=新的WebClient();
client.DownloadStringCompleted+=新的DownloadStringCompletedEventHandler(DownloadStringCallback2);
client.DownloadStringAsync(u);
}
私有void DownloadStringCallback2(对象发送方,DownloadStringCompletedEventArgs e){
//data.Text=e.结果;
data.Text=Regex.Replace(例如,Result,“]*>”,“”);
}
私有无效但单击(对象发送者,路由目标){
getpage();
}

要获取身体部位,我应该做什么?是否有其他方法可以做到这一点

请在回调函数中尝试以下代码

string html = e.Result;
       string theBody = "";
       RegexOptions options = RegexOptions.IgnoreCase | RegexOptions.Singleline;
       Regex regx = new Regex("<body>(?<theBody>.*)</body>", options);
       Match match = regx.Match(html);
       if (match.Success)
       {
           theBody = match.Groups["theBody"].Value;
       }
string html=e.结果;
字符串theBody=“”;
RegexOptions options=RegexOptions.IgnoreCase | RegexOptions.Singleline;
Regex regx=new Regex((?*),选项);
Match=regx.Match(html);
如果(匹配成功)
{
theBody=match.Groups[“theBody”].Value;
}

“theBody”变量将包含body标记的内部html。

看到这一点,我没有问如何过滤。我不明白为什么我没有获得网站的body部分。body部分是通过正则表达式替换方法删除的。在这个问题上,您可以使用其他方法来实现这一点。你在你的问题中提到过任何其他方式,当我没有使用替换方法时,我仍然没有得到结果中的任何部分;(整个html页面)我仍然没有得到身体部分好吧,我得到了你的代码的结果,我忘了在我的文本块中打印