I am trying to write a code to look up the weather in any given city. I have found I can do this using weather.com rss feeds and extracting the relevant strings. But to find the code for each individual city I have had to google search the site, the city etc. I think I need to use a web browser control to process the url of a "I'm feeling lucky" google search to get the weather.com address for the given city....
my problem is that I want to get rid of the web browser / or blank it out when the page loads and I have the url. BUT I want to be able to use the same search again if I need to, so i used a hidden web browser and am trying to get it to return back to about:blank after I get the URL.
my code so far is:
Public Class Form1
Public urlout As String = ""
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
WebBrowser1.ScriptErrorsSuppressed = True
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim city As String = TextBox1.Text
Dim weathurl As String = "http://www.google.com/search?ie=UTF-8&oe=UTF-8&sourceid=navclient&btnI=1&q=" & city & "+weather+site%3Aweather.com"
WebBrowser1.Navigate(weathurl)
End Sub
Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
While WebBrowser1.IsBusy = False
If WebBrowser1.Url.ToString().IndexOf("weather.com") Then
urlout = (WebBrowser1.Url.ToString())
WebBrowser1.Navigate("about:blank")
TextBox2.Text = urlout
ElseIf WebBrowser1.Url.ToString().IndexOf("about:blank") Then
Exit While
End If
End While
End Sub
End Class
However I get with this I get stuck in some sort of odd loop where the whole thing hangs and outputs :"Additional Information: Transition into COM context 0x69f138 for this RuntimeCallableWrapper failed with the following error: System call failed. (Exception from HRESULT: 0x80010100 (RPC_E_SYS_CALL_FAILED))."
If I get rid of ElseIf WebBrowser1.Url.ToString().IndexOf("about:blank") Then
Exit While
The outputted URL gives about:blank..... I don't know if the document completed event is being access when about:blank is loaded????
Any help or ideas would be appreciated! I thought this would be the easy bit!:sick:
my problem is that I want to get rid of the web browser / or blank it out when the page loads and I have the url. BUT I want to be able to use the same search again if I need to, so i used a hidden web browser and am trying to get it to return back to about:blank after I get the URL.
my code so far is:
Public Class Form1
Public urlout As String = ""
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
WebBrowser1.ScriptErrorsSuppressed = True
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim city As String = TextBox1.Text
Dim weathurl As String = "http://www.google.com/search?ie=UTF-8&oe=UTF-8&sourceid=navclient&btnI=1&q=" & city & "+weather+site%3Aweather.com"
WebBrowser1.Navigate(weathurl)
End Sub
Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
While WebBrowser1.IsBusy = False
If WebBrowser1.Url.ToString().IndexOf("weather.com") Then
urlout = (WebBrowser1.Url.ToString())
WebBrowser1.Navigate("about:blank")
TextBox2.Text = urlout
ElseIf WebBrowser1.Url.ToString().IndexOf("about:blank") Then
Exit While
End If
End While
End Sub
End Class
However I get with this I get stuck in some sort of odd loop where the whole thing hangs and outputs :"Additional Information: Transition into COM context 0x69f138 for this RuntimeCallableWrapper failed with the following error: System call failed. (Exception from HRESULT: 0x80010100 (RPC_E_SYS_CALL_FAILED))."
If I get rid of ElseIf WebBrowser1.Url.ToString().IndexOf("about:blank") Then
Exit While
The outputted URL gives about:blank..... I don't know if the document completed event is being access when about:blank is loaded????
Any help or ideas would be appreciated! I thought this would be the easy bit!:sick: