Hi,
I am writing some code to get some data from google suggest api. I am a noob so have run into a problem as my code is retuning blank data.
Here is my code
public XmlDocument GetData(string phrase)
{
XmlDocument theXML = new XmlDocument();
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://google.com/complete/search?output=toolbar&q=" + phrase.ToString());
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
// Get the stream associated with the response.
Stream receiveStream = response.GetResponseStream();
theXML.Load(receiveStream);
response.Close();
}
catch (Exception e)
{
}
return theXML;
}
private void btnGenerate_Click(object sender, EventArgs e)
{
XmlDocument theXML = GetData("keyword");
XmlNode theXmlNode = theXML.DocumentElement;
XmlNodeList theXmlNodeList = theXmlNode.SelectNodes("/toplevel/CompleteSuggestion");
for (int x = 0; x < theXmlNodeList.Count; x++)
{
MessageBox.Show(theXmlNodeList.Item(x).InnerText);
}
}
I just made it so that it would return the data in a message box for testing purposes. All message boxes are blank so I must have made a mistake somewhere.
Can anyone help please?
Thanks