Click here to Skip to main content
15,892,737 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to get movie names for folders on my local machine using vb.net. is there a better way then what i am using. I am currently trying to open the webpage, read the entire response as a string, convert the string to a webbrowser object, convert the webbrowser.document to htmldocument and then search for the movie names in the response. However, when i use the webbrowser object without adding a control to my form it does not function.

If there is a betterway, please help. This looks very poorly written and must have a better way of reading the information.

The code i am using is below, the code is incomplete because i have been trying to get it functional trying different variation, but it shows what i am doing.

VB
Public Function get_New_Folder_Names(directory As DirectoryInfo) As List(Of String)
    Dim new_Names As New List(Of String)
    Dim SearchAddress As String = "http://www.imdb.com/find?q="
    Dim endOfAddress As String = "&s=all"
    Dim url As String = "about:blank"
    url = SearchAddress

    Dim words() As String
    words = directory.Name.Split(" ")
    If words.Count <= 1 Then words = directory.Name.Split(".")

    For Each word As String In words
        '( = %28
        ') = %29
        If word.Contains("(") Then
            Dim fixword As String = Nothing
            For letter As Integer = 0 To word.Count - 1
                If word(letter) = "(" Then
                    fixword &= "%28"
                Else
                    fixword &= word(letter)
                End If
            Next
            word = fixword
        End If
        If word.Contains(")") Then
            Dim fixword As String = Nothing
            For letter As Integer = 0 To word.Count - 1
                If word(letter) = ")" Then
                    fixword &= "%29"
                Else
                    fixword &= word(letter)
                End If
            Next
            word = fixword
        End If
        url &= word & "+"
    Next
    If url(url.Length - 1) = "+" Then url = url.Remove(url.Length - 1)
    url &= endOfAddress


    Navigate(url)

    new_Names.Add("Fix This!")
    Return new_Names
End Function

Private Sub Navigate(ByVal address As String)

    If String.IsNullOrEmpty(address) Then Return
    If address.Equals("about:blank") Then Return
    If Not address.StartsWith("http://") And _
        Not address.StartsWith("https://") Then
        address = "http://" & address
    End If
    ' AscW("a")
    ' AscW("z")
    Try
        ' Get HTML data
        Dim client As New WebClient()
        Dim data As Stream = client.OpenRead(address)
        Dim reader As StreamReader = New StreamReader(data)
        Dim str As String = ""
        str = reader.ReadToEnd
        Dim wb As New WebBrowser
        wb.DocumentText = str
        Dim doc As HtmlDocument = wb.Document
        Dim htmlelmcoll As HtmlElementCollection = doc.GetElementsByTagName("")


    Catch ex As System.UriFormatException
        Return
    End Try


End Sub
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900