收集Youtube用户名 [英] Gathering Youtube usernames

查看:210
本文介绍了收集Youtube用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个小应用程序,用于通过关键字收集youtube用户名.用户将在应用程序中进行搜索,并显示带有链接以订阅其频道的用户名列表.

我有此代码,但这仅收集视频标题,我需要收集用户名.

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.

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.

推荐答案

一种方法是分析DOM的内容并查找包含所需信息的元素.

例如;每个搜索项都包装在具有类result-itemdiv 中,其中包含2个子容器,一个用于缩略图,一个用于详细信息,在详细信息部分中有一个跨度为"username-prepend"后紧跟一个包含用户链接和用户名的链接.您可以轻松地从Webbrowser.document
中提取该信息
另一种方法是研究各种YouTube开发人员API,并查看如何使用它们直接集成到您的应用中.
http://code.google.com/apis/youtube/getting_started.html#data_api [ ^ ]
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[^]


这篇关于收集Youtube用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆