I wanted to get elements and tags inside of youtube search results with below code for windows phone application.
public partial class Page1 : PhoneApplicationPage
{
string keyword;
public Page1()
{
InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
NavigationContext.QueryString.TryGetValue("parameter", out keyword);
LoadResults();
}
public void LoadResults()
{
WebClient codeSampleReq = new WebClient();
codeSampleReq.DownloadStringCompleted += codeSampleReq_DownloadStringCompleted;
codeSampleReq.DownloadStringAsync(new Uri("https://www.youtube.com/results?search_query=" + keyword));
}
void codeSampleReq_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
try
{
HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
htmlDoc.OptionFixNestedTags = true;
htmlDoc.LoadHtml(e.Result);
HtmlNode divContainer = htmlDoc.GetElementbyId("a");
if (divContainer != null)
{
HtmlNodeCollection nodes = divContainer.SelectNodes("a");
foreach (HtmlNode trNode in nodes)
{
}
}
}
catch (Exception ex)
{
MessageBox.Show("Unable to download" + ex.Message);
}
}
}
and get exception below:
{System.Net.WebException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound. at System.Net.Browser.ClientHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) at System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClasse.b__d(Object sendState) at System.Net.Browser.AsyncHelper.<>c__DisplayClass1.b__0(Object sendState) --- End of inner exception stack trace --- at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state) at System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result) at System.Net.WebClient.DownloadBitsResponseCallback(IAsyncResult result)}
does anybody know why server return 404 not found?
note: Keyword can only be string like "ali, veli, kadir" or something else.