Introduction
This will show you how to get images, links and source code from a website using a web-browser control. This can be added to an external web-browser project.
Using the Code
The code requires WebBrowser
, TabControl
, Richtextbox
, PictureBox
, (2x)ListBox
.
Double click the WebBrowser
control and in the DocumentCompleted Sub
, add the following code:
RichTextBox.Text = WebBrowser.DocumentText.ToString For Each ele As HtmlElement In WebBrowser.Document.Links
Dim eletarget As String = ele.GetAttribute("href")
LINKS-ListBox.Items.Add(eletarget) Next
For Each ele As HtmlElement In WebBrowser.Document.All
If ele.GetAttribute("src").ToLower.Contains(".jpg") Then
Dim imgsrc As String = ele.GetAttribute("src")
IMAGES-ListBox.Items.Add(imgsrc) End If
If ele.GetAttribute("src").ToLower.Contains(".png") Then
Dim imgsrc As String = ele.GetAttribute("src")
IMAGES-ListBox.Items.Add(imgsrc) End If
If ele.GetAttribute("src").ToLower.Contains(".gif") Then
Dim imgsrc As String = ele.GetAttribute("src")
IMAGES-ListBox.Items.Add(imgsrc) End If
If ele.GetAttribute("src").ToLower.Contains(".bmp") Then
Dim imgsrc As String = ele.GetAttribute("src")
IMAGES-ListBox.Items.Add(imgsrc) End If
Next
Now double click the ListBox
which will get the images and in the Click Sub
, add the following code:
PREVIEW-PictureBox.ImageLocation = IMAGES-ListBox.SelectedItem.ToString
Go to the DoubleClick Sub
of the same ListBox
as before and insert the following code:
WebBrowser.Navigate(IMAGES-ListBox.SelectedItem.ToString)
Finally, double click the ListBox
which will get the links and in the DoubleClick Sub
, add the following code:
WebBrowser.Navigate(LINKS-ListBox.SelectedItem.ToString)
Points of Interest
As you can see, the code is very simple and very easy to build onto. It doesn't have to be links or images, it can also be other files and resources.