Quantcast
Viewing all articles
Browse latest Browse all 27020

VS 2010 Trying to extract a CSS style using VB. What am I doing wrong?

Hey guys,

On form load I am using a web browser control to navigate to a specific webpage...

Code:

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        WebBrowser1.Navigate("http://www.website.com")

    End Sub

Then in the web browser's document completed event, I am doing this...

Code:

    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted

        Try

            Dim ExtractedStyle As String = WebBrowser1.Document.GetElementById("wrapper").Style("background")
            TextBox1.Text = ExtractedStyle

        Catch ex As Exception

            MessageBox.Show(ex.ToString)

        End Try


    End Sub


Problem is, it is throwing the following exception every time...

Quote:

System.InvalidCastException: Conversion from string "background" to type "integer" is not valid. ---> System.FormatException: Input string was not in a correct format.
I don't understand where an integer is coming from, as "ExtractedStyle" is a string, and the style I am trying to extract ("background") is also a string... or so I thought.

Also, I double checked the HTML source code on that page, and there is definitely an ID named "wrapper" that uses a CSS style named "background".

What am I missing here?

Or is this not the correct way to extract a style from a webpage?

Viewing all articles
Browse latest Browse all 27020

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>