Reputation: 43
i fetch data from http://www.vaktija.ba/mobile/ but i dont get the body part of the website i just get title
here is my code
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();
}
what should i do to get body part are there any other way to do that
Upvotes: 0
Views: 73
Reputation: 2244
Try the following code in your call back function.
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;
}
"theBody" variable will have inner html of body tag.
Upvotes: 1