c# - How can I loop clicking on a button -


i'm using geckofx , regex in c# make youtube video channel scraper. want url of videos selected channel.

i want use geckofx (the firefox rendering engine) go videos section , click load more button until every video shows.

i using code click load more on , over:

javascript:(function() {    var loadbutton, intervalclb;   intervalclb = setinterval(_clickloadbutton, 100);    function _clickloadbutton() {     loadbutton = document.getelementsbyclassname('load-more-button');     if (loadbutton.length > 0) {       loadbutton[0].click();     }     else {       clearinterval(intervalclb);       alert('finished - clicked "load more" buttons.');     }   } })(); 

i want write in c#.

my code looks like:

system.threading.thread.sleep(1000);  geckodocument document = geckowebbrowser1.document;  geckohtmlelement male = (geckohtmlelement)document.getelementsbyclassname("load-more-button")[0];  if ( male != null ) {     male.click(); } 

but clicks load more once after 1 second.

how can make loop until load more button disappears?

  timer timer = new timer(1000);   timer.elapsed += ( sender, e ) => {      geckodocument document = geckowebbrowser1.document;      geckohtmlelement male = (geckohtmlelement)document.getelementsbyclassname("load-more-button")[0];      if ( male != null ) {         male.click();     }   };   timer.start(); 

but practical side recommend youtube api: https://developers.google.com/youtube/v3/code_samples/dotnet


Comments