Click here to Skip to main content
15,884,629 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to make a small app for gather the youtube username by keywords. The users will make a search in the app and will appear the list of usernames with a link to subscribe to their channels.

I have this code but this gather only video titles and I need gather the usernames.

VB
Public Class form1
    Public pagenumber As Integer
    Public farmpage As Integer
    Public hola As String

    Public Sub changepage()
        If farmpage < pagenumber Then
            Dim keyword As String
            Dim urlstring As String
            keyword = TextBox1.Text.ToString
            urlstring = ("http://www.youtube.com/results?search_query=" + keyword + "&page=" + farmpage.ToString)
            WebBrowser1.Navigate(urlstring)
            farmpage = farmpage + 1
        End If
    End Sub

    Public Sub scrape_keywords()
        If farmpage < pagenumber Then
            Try
                Dim theelementcollection As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("a")
                For Each curElement2 As HtmlElement In theelementcollection
                    Name = curElement2.GetAttribute("title")
                    kfarm.Items.Add(Name)
                    cleankeywords(kfarm)
                Next
            Catch
            End Try
        Else
        End If
    End Sub

    Private Sub GButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GButton1.Click
        Me.Close()
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        changepage()
        scrape_keywords()
    End Sub

    Private Sub GButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GButton3.Click
        Timer1.Stop()
        farmpage = 1
    End Sub

    Private Sub GButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GButton2.Click
        Timer1.Start()
        farmpage = 1
        changepage()
        pagenumber = TextBox2.Text
    End Sub

    Function cleankeywords(ByVal listbox As ListBox) As Boolean
        Dim i, j As Integer
        Dim Arr As New ArrayList
        Dim ItemFound As Boolean
        For i = 0 To kfarm.Items.Count - 1
            ItemFound = False
            For j = 0 To i - 1
                If kfarm.Items.Item(i) = kfarm.Items.Item(j) Then
                    ItemFound = True
                    Exit For
                End If
            Next j
            If Not ItemFound Then
                Arr.Add(kfarm.Items.Item(i))
            End If
        Next i
        kfarm.Items.Clear()
        kfarm.Items.AddRange(Arr.ToArray)
        Arr = Nothing
        kfarm.Items.Remove(" BrowseUpload Create AccountSign In Search")
        kfarm.Items.Remove("")
        kfarm.Items.Remove("YouTube home")
    End Function

    Private Sub AToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AToolStripMenuItem.Click
        Dim FileNumber As Integer = FreeFile()
        FileOpen(FileNumber, "Keywords.txt", OpenMode.Output)
        For Each Item As Object In kfarm.Items
            PrintLine(FileNumber, Item.ToString)
        Next
        FileClose(FileNumber)
        MsgBox("Keywords Will Be Saved In The Same Spot Where You Have Youtube App!", MsgBoxStyle.Information, "Save Helper")
    End Sub

    Private Sub RemoveAllToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RemoveAllToolStripMenuItem.Click
        kfarm.Items.Clear()
    End Sub

    Private Sub RemoveSelectedToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RemoveSelectedToolStripMenuItem.Click
        kfarm.Items.Remove(kfarm.SelectedItem)
    End Sub

    Private Sub CopySelectedToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CopySelectedToolStripMenuItem.Click
        Clipboard.Clear()
        Clipboard.SetText(kfarm.SelectedItem)
    End Sub
End Class



Please help me.
Posted

1 solution

One method would be to anaylse the contents of the DOM and look for the elements that contain the information you want.

For Example; Every search item is wrapped in a div that has the class "result-item", contained within that are 2 child containers, one for the thumbnail and one for the details, in the details section there is a span with the class "username-prepend" immediately followed by a link containing the user link and the username. You could easily extract that info from the Webbrowser.document

The alternate method would be to investigate the various YouTube developer API's and see how you could use these to integrate directly into your App.
http://code.google.com/apis/youtube/getting_started.html#data_api[^]
 
Share this answer
 

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