0

Hi im im trying to get attributes from two diffrent tag names..

 <img class="chimg" alt="SOME TEXT" src=" #1 IMAGE LINK TO GET"/> <span>" #2 TIME TO GET" </span>" SOME TEXT "</a> </h3> <div> <a  href=' #4 LINK TO
         GET' onclick="window.open('Some link'); return true;" title=' #3 TITLE TO GET' >SOME TEXT</a>

I WANT TO PUT THESE IN ORDER FOR EACH LINK

DataGridView1.Rows.Add(""IMAGE LINK"", ""TIME TO GET"", ""TITLE TO GET"", ""LINK TO GET"" )
this is what i have so far

 Dim ElementCollection As Windows.Forms.HtmlElementCollection   
            ElementCollection = WebBrowser1.Document.GetElementsByTagName("a")       
            For Each curElement As HtmlElement In ElementCollection
                DataGridView1.Rows.Add(curElement.GetAttribute("title"), curElement.GetAttribute("href"))
            Next

Please help..

2
Contributors
1
Reply
74
Views
11 Months
Discussion Span
Last Post by Xavier_5
0
            For Each link In webbrowser1.Document.All 
                If link.innerHTML IsNot Nothing Then
                    Dim sTag As New StringBuilder(link.innerHTML.ToString)
                    If Regex.IsMatch(sTag.ToString, "^(\s*\<)") Then
                        Dim posGT As Int32 = InStr(sTag.ToString, ">")
                        If posGT Then
                            sTag.Remove(posGT - 1, sTag.Length - posGT + 1)
                        End If
                        Dim m As Match = Regex.Match(sTag.ToString, "^\s*\<\w+\s*")
                        If m.Success Then
                            sTag.Remove(0, m.Length)
                            Dim vNames(-1), vValues(-1) As String, iv As Int32 = 0
                            m = Regex.Match(sTag.ToString, "\w+")
                            Do While m.Success
                                ReDim Preserve vNames(iv), vValues(iv)
                                vNames(iv) = m.Value
                                sTag.Remove(0, m.Index + m.Length)
                                m = Regex.Match(sTag.ToString, "\s*\=\s*")
                                If m.Success Then
                                    sTag.Remove(0, m.Length)
                                    Dim sA As String = sTag.Chars(0)
                                    If sA = """" OrElse sA = "'" Then
                                        Dim pos As Int32 = InStr(sTag.ToString.Substring(1), sA)
                                        vValues(iv) = sTag.ToString.Substring(1, pos - 1)
                                        sTag.Remove(0, pos)
                                    Else
                                        m = Regex.Match(sTag.ToString, "\w+")
                                        If m.Success Then
                                            vValues(iv) = m.Value
                                            sTag.Remove(0, m.Index + m.Length)
                                        Else
                                            vValues(iv) = "" ' attribute's value is missing
                                        End If
                                    End If
                                Else
                                    vValues(iv) = "" ' attribute's value is missing
                                End If
                                iv += 1
                                m = Regex.Match(sTag.ToString, "[^ \>\""\'\=]+")
                            Loop
                            Array.Sort(vNames, vValues)
                            ' "
                            For i As Int32 = 0 To iv - 1
                                '"'Trace.WriteLine(vNames(i) + "=" + vValues(i))
                                DataGridView1.Rows.Add(vNames(i),vValues(i)
                            Next
                        End If
                    End If
                End If
            Next

Edited by Xavier_5: extra commenting (in green color) after the first '

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.