Im working on a project , and i have an obstacle about webbrowser tool in vb.net . I want to show a msgbox when the user is in a specific site , how can this be done ? , in another words , how can i get the current url in the webberowser tool in vb.net?
Webbrowser.Url is a Uri, not a string. So compare it with a Uri.
If WebBrowser1.Url = New Uri("http://stackoverflow.com") Then
I would say you should check the Host of the URI, that way it works for all of the URLs and not just the top level for a given site:
Private Sub Button1_Click_1( sender As System.Object, e As System.EventArgs) Handles Button1.Click
WebBrowser1.Navigate("http://www.stackoverflow.com")
End Sub
Private Sub WebBrowser1_DocumentCompleted( sender As System.Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
If WebBrowser1.Url.Host = "stackoverflow.com"
MessageBox.Show("You are at stack overflow")
End If
End Sub
Is this what you mean?
Dim browser As String
browser = TextBox1.Text
WebBrowser1.Navigate(browser)
MsgBox("Your visiting " & browser)
End Sub
Related
IN CODE: At 1 browser clicks a button and takes a time to load. AT 2 i get source code of page in RichTextBox1. but as page take time to load code 2 starts before completion of 1 because of that i am unable to get the web page source at desired state? what do i do ? i want to get web page source when web browser completely loads after the execution of code 1.
i have tried
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.WebBrowser1.Navigate("some website")
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
WebBrowser1.Document.GetElementById("notification_address").SetAttribute("value", TextBox1.Text)
WebBrowser1.Document.Forms(0).InvokeMember("submit") (-----1-----)
RichTextBox1.Text = WebBrowser1.DocumentText (-----2-----)
End Sub
You can use the DocumentCompleted event.
https://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.documentcompleted(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1
Private Sub DocumentCompleted(ByVal sender As Object, _
ByVal e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
' this is where your code goes RichTextBox1.Text = WebBrowser1.DocumentText (-----2-----)
End Sub
I have a richtextbox that contains URLs and a webborwser and a button. I would like that everytime i press the button, my webbrowser navigate to each url (one URL by line).
Here is my code :
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
For i As Integer = 0 To RichTextBox1.Lines.Count - 1
WebBrowser1.Navigate(RichTextBox1.Lines(i))
Next
End Sub
My problem : It seems that the webbrowser navigate directly (cause other URL are loaded too fast) to the last website contained in the richtextbox...
How can i ask my webbrowser to wait the button to be clicked to navigate to the next URL ?
Public Shared i As Integer = 0
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
WebBrowser1.Navigate(RichTextBox1.Lines(i))
i = i + 1
End Sub
thanks again #jmcilhinney
I'm new in VB.NET , i try to make spam wall (fb) in vb.net so , this my code,
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Process.Start("https://graph.facebook.com/" & (TextBox2.Text) & "/photos?url=" & (TextBox3.Text) & "&method=POST&message=" & (TextBox4.Text) & "a&access_token=" & (TextBox1.Text))
End Sub
End Class
after that , i'm click button 1 , and i see new web page in my browser.
so , i want to make if i click button 1 , there no webpage in my browser.
if don't wanna open the browser then use webbrowser control like so
Private webbrows As New WebBrowser
private sub form_load(snder......
dim _url as string = "your url that mostly wont work"
webbrows.Navigate(_url)
' if you use vb2010 then you have lambada expressions
AddHandler webbrows.DocumentCompleted, Sub(sd As Object, e4 As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)
' a check that the page fully loaded
If e4.Url.ToString <> _url Then Exit Sub
sd.dispose()
End Sub
end sub
Ok so I have been have alot of trouble with the
Web browser control on a few applications I am working on.
All of them share the same issue. I want to have the application navigate s webpage a read the write the text in the page source to a variable. I also need to be able to save the files afterwards.
Some Source code:
Public Class Form4
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MyFolderBrowser As New System.Windows.Forms.FolderBrowserDialog
MyFolderBrowser.Description = "Select the Folder"
MyFolderBrowser.ShowNewFolderButton = False
Dim dlgResult As DialogResult = MyFolderBrowser.ShowDialog()
If dlgResult = Windows.Forms.DialogResult.OK Then
TextBox1.Text = MyFolderBrowser.SelectedPath
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If TextBox1.Text = "" Then
MessageBox.Show("You have to select a directory!")
Else
WebBrowser1.Navigate("www.realmofthemadgod.com/version.txt")
System.Threading.Thread.Sleep(3000)
Dim PageSource As String = WebBrowser1.Document.Body.InnerText
WebBrowser1.Navigate("http://www.realmofthemadgod.com/AssembleeGameClient" & PageSource & ".swf")
End If
End Sub
End Class
The first thing I am having an issue with is that it never waits for the webpage to load before pulling the Document text. I have tried many different ways to from different solutions people have posted to get around this. Oddly it always seems to work if I do it a second time.
And I want to save the final resulting webpage as an swf to the selected directory if Button2 is clicked.
Thanks for any help I have been looking for this everywhere
Welcome to the dark art of web scraping. First off, I would recommend using WebClient instead of WebBrowser as it has discrete methods for downloading data from web sites. It looks like your version.txt only contains the data you want (and no extraneous html) so we can download it directly. If you needed to parse html I would use HtmlAgilityPack. Untested code to get you started:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If TextBox1.Text = "" Then
MessageBox.Show("You have to select a directory!")
Else
Using wc as New WebClient()
Dim version = wc.DownloadString("www.realmofthemadgod.com/version.txt")
Dim swf = "http://www.realmofthemadgod.com/AssembleeGameClient" + version + ".swf"
wc.DownloadFile(swf,"c:\temp\myswf.swf")
End Using
End If
End Sub
I'm trying to create a little executable that when launched opens an IE browser to various websites like news sites all in different tabs. for example, a tab for wsj, nytimes, etc. How do I access IE with vb.net? What reference do I need to add? I can't find any sample code that I can make work I think it is because I am missing a library in my assembly?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
OpenURL("www.google.com")
End Sub
Private Sub OpenURL(ByVal URL As String)
System.Diagnostics.Process.Start(URL)
End Sub
'Or
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim TheBrowser As Object = CreateObject("InternetExplorer.Application")
TheBrowser.Visible = True
TheBrowser.Navigate("www.google.com")
End Sub
'Or add Reference SHDocVw.dll By Browsing System32
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim TheBrowser = New SHDocVw.InternetExplorerMedium
TheBrowser.Visible = True
TheBrowser.Navigate(URL:="http://www.google.com")
End Sub
You can't open them in tabs:
Programmatically open a new tab in ie7
Is your application a console application? You can't create multiple tabs, but you can use a System.Diagnostics.Process to launch individual instances of Internet Explorer. You should be able to simply specify the full address of the website as the Process to run, similar to how you can put "http://www.wsj.com" into a run prompt, which will launch your default browser with the Wall Street Journal's website.
If you are using WinForms, you could always use a WebBrowser control, but that has limitations for tabs as well.