2017-08-28 6 views
-1

私はビデオに自動的にコメントするプログラムvb.netを作ろうとしています。これまでのところ、私は持っています:Youtubeのコメントボタンをクリックする

私はそれがサイトのコメントボックスをクリックする必要があります。私はこれを行う方法は -

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
    WebBrowser1.Document.GetElementById(".comment-simplebox-renderer-collapsed-content").InvokeMember("click") 
End Sub 

しかし、それだけでエラーを与えると思った。私は本当にこれを行う方法に失われているので、どんな助けも大いに評価されるでしょう。

+0

をプロジェクトにウェブブラウザを追加し、名前を付け、「ブラウザ」[尋ねる] ...すべての詳細を記載してください。何のエラー?あなたが努力を怠ると、私たちはそうすることはまずありません。 –

+0

HttpWebRequestは、あなたが望むことを行うための最良の方法です。私は本当にそのような状況のためにWebBrowserを好まない。 – Youssef13

+1

私はyoutubeがそれに満足しているとは思わない。彼らはそれを行うためのAPIを提供しています。 –

答えて

0

はそれは読むために本当に重要だ

browser.Navigate("https://www.youtube.com/watch?v=OQ4oaLUilBc") 
    While browser.ReadyState <> WebBrowserReadyState.Complete 
     Application.DoEvents() 
    End While 
    Dim comment_wrote As Boolean = False 
    Dim comment_done As Boolean = False 
    While comment_wrote = False 
     For Each altelm As HtmlElement In browser.Document.GetElementsByTagName("DIV") 
      If altelm.GetAttribute("classname").ToString = "comment-simplebox-renderer-collapsed comment-simplebox-trigger" Then 
       altelm.Focus() 
       altelm.InvokeMember("click") 
      End If 

      If altelm.GetAttribute("classname").ToString = "comment-simplebox-text" And comment_wrote = False Then 
       altelm.Focus() 
       altelm.InvokeMember("click") 
       SendKeys.SendWait("I love this song!") 
       comment_wrote = True 
      End If 

     Next 
     Application.DoEvents() 
    End While 
    While comment_done = False 
     For Each altelm As HtmlElement In browser.Document.GetElementsByTagName("BUTTON") 
      If altelm.GetAttribute("classname").ToString = "yt-uix-button yt-uix-button-size-default yt-uix-button-primary yt-uix-button-empty comment-simplebox-submit yt-uix-sessionlink" And comment_done = False Then 
       altelm.Focus() 
       altelm.InvokeMember("click") 
       comment_done = True 
      End If 
      Application.DoEvents() 
     Next 
     Application.DoEvents() 
    End While 
関連する問題