从网站获取数据

时间:2014-07-01 11:12:33

标签: c# windows-phone-8

我从http://www.vaktija.ba/mobile/获取数据,但我没有得到网站的正文部分 我得到冠军

这是我的代码

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();
}

我该怎样做以获得身体部位还有其他方法可以做到这一点

1 个答案:

答案 0 :(得分:1)

在回叫功能中尝试以下代码。

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;
       }

&#34;汽车美容&#34;变量将具有body标签的内部html。

相关问题