|
-
May 12th, 2013, 06:13 PM
#1
Thread Starter
New Member
[RESOLVED] Help with frustration.
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!
-
May 13th, 2013, 12:59 AM
#2
Re: Help with frustration.
I would suggest a couple things here:
1) Firstly, please use code tags. That's probably the reason why nobody else has responded to your thread. The code is not properly indented, and it's not in code tags either. This makes the code very frustrating for someone to read, and lots of people ignore threads like this because of that.
2) Look into WebRequests. This WebBrowser strategy is nonsense.
<<<------------
.NET Programming (2012 - 2018)
®Crestron - DMC-T Certified Programmer | Software Developer <<<------------
-
May 13th, 2013, 04:07 AM
#3
Re: Help with frustration.
You may be able to do what you're trying without the web browser by using the HttpWebRequest class.
-
May 13th, 2013, 04:56 PM
#4
Thread Starter
New Member
Re: Help with frustration.
 Originally Posted by Niya
You may be able to do what you're trying without the web browser by using the HttpWebRequest class.
Thanks. Looked this up and it worked a charm. I'll make sure I use tags next time!
Thanks x
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|