person66

Albert Vote Code

Nov 21st, 2013
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.39 KB | None | 0 0
  1. private void webBrowser1_DocumentCompleted_Vote()
  2. {
  3.     //Click the vote button
  4.     HtmlElementCollection elc = webBrowser1.Document.GetElementsByTagName("input");
  5.     foreach (HtmlElement el in elc)
  6.     {
  7.         if (el.GetAttribute("type").Equals("submit") && el.GetAttribute("value").Equals("Vote now"))
  8.         {
  9.             el.InvokeMember("Click");
  10.         }
  11.     }
  12.  
  13.     //Wait to make sure vote has gone through. This loop will stop after 10 unsuccessful checks
  14.     bool voted = false;
  15.     for (int i = 0; i < 10; i++)
  16.     {
  17.         //Sleep for 1 second, then check
  18.         Thread.Sleep(1000);
  19.        
  20.         //The innerHTML of your webBrowser control will only have the 'day today has-voted' text
  21.         //once the vote has gone through. (or if you have already voted today I suppose. You may
  22.         //want to check for that somewhere I guess. The button click might not work if you have
  23.         //already voted, sooo yeah. Not sure.)
  24.         //I removed spaces because there was weird formatting with multiple spaces on this section
  25.         //of the page, so it is best to just remove them before the check to avoid issues
  26.         if (webBrowser1.Document.Body.InnerHtml.Replace(" ", "").Contains("daytodayhas-voted"))
  27.         {
  28.             //The vote has gone through. Set voted to true and break out of the for loop.
  29.             voted = true;
  30.             break;
  31.         }
  32.     }
  33.  
  34.     //If voted is not true that means the loop ran 10 times without success.
  35.     if (!voted)
  36.     {
  37.         MessageBox.Show("Error: Voting failed");
  38.         return;
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment