Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. from selenium import webdriver
  2. from selenium.webdriver.common.keys import Keys
  3. from time import sleep
  4. from selenium.common.exceptions import NoSuchElementException
  5. from selenium.common.exceptions import InvalidElementStateException
  6.  
  7. x = webdriver.Chrome(executable_path='G:\Python\Driver\chromedriver')
  8.  
  9. x.get('https://www.omegle.com/')
  10. print("Visit Omegle")
  11. sleep(10)
  12. new_chat = x.find_element_by_id('textbtn').click()
  13. print("Start New Chat")
  14. chat_total = 0
  15. chat_completed = 0
  16. chat_closed = 0
  17. count = 0
  18.  
  19. def restart():
  20. global chat_total, chat_completed, chat_closed, count
  21. next_chat = x.find_element_by_class_name('disconnectbtn').click()
  22. sleep(1)
  23. chat_total +=1
  24.  
  25. def send_new(textmsg):
  26. msg = x.find_element_by_xpath('/html/body/div[5]/div/div/div[2]/table/tbody/tr/td[2]/div/textarea')
  27. send_msg = x.find_element_by_class_name('sendbtn')
  28. msg.send_keys(textmsg)
  29. send_msg.click()
  30.  
  31. def bot_start():
  32. global chat_total, chat_completed, chat_closed, count
  33. while count == 0:
  34. try:
  35. chat_closed = chat_total - chat_completed
  36. print("Total Chat: " + str (chat_total) + " - Closed: " + str (chat_closed) + " - Completed: " + str (chat_completed))
  37. #print("Start New Chat")
  38. sleep(5)
  39.  
  40. if ("Stranger has disconnected." in x.page_source) or ("You have disconnected." in x.page_source):
  41. restart()
  42. continue
  43. else:
  44. send_new("F17")
  45. sleep(3)
  46. if ("Stranger has disconnected." in x.page_source) or ("You have disconnected." in x.page_source):
  47. restart()
  48. continue
  49. else:
  50. send_new("Ho deciso di fare una raccolta di tutte le mie foto HOT")
  51. sleep(3) #http://bit.ly/2r6CFD4
  52. if ("Stranger has disconnected." in x.page_source) or ("You have disconnected." in x.page_source):
  53. restart()
  54. continue
  55. else:
  56. send_new("se ti va di vederla e darmi un parere la trovi qua: https://about.me/anna_tonarelli")
  57. sleep(3)
  58. if ("Stranger has disconnected." in x.page_source) or ("You have disconnected." in x.page_source):
  59. restart()
  60. continue
  61. else:
  62. send_new("fammi sapere che ne pensi, ci ho messo impegno")
  63. sleep(3)
  64. if ("Stranger has disconnected." in x.page_source) or ("You have disconnected." in x.page_source):
  65. restart()
  66. continue
  67. else:
  68. #print("Finish Chat")
  69. chat_completed +=1
  70. next_chat = x.find_element_by_class_name('disconnectbtn').click()
  71. sleep(1)
  72. next_chat = x.find_element_by_class_name('disconnectbtn').click()
  73. sleep(1)
  74. next_chat = x.find_element_by_class_name('disconnectbtn').click()
  75.  
  76. except NoSuchElementException:
  77. continue
  78. except InvalidElementStateException:
  79. restart()
  80.  
  81. bot_start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement