meta_move.py 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. #import redis
  2. import time
  3. import traceback
  4. #import json
  5. from selenium import webdriver
  6. from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
  7. import time
  8. import os
  9. from selenium.webdriver.common.keys import Keys
  10. from selenium.webdriver.support.ui import WebDriverWait
  11. from selenium.webdriver.common.by import By
  12. from selenium.webdriver.support import expected_conditions as EC
  13. import random
  14. import time
  15. import sys
  16. import codecs
  17. import random
  18. import os
  19. import time
  20. #import pyautogui
  21. driver=None
  22. def re_get_webdriver():
  23. global driver
  24. result=[]
  25. if driver is not None:
  26. print('closing....')
  27. driver.quit()
  28. os.system('killall chrome')
  29. print('quit....')
  30. driver=None
  31. try:
  32. # ua = userAgents()
  33. # user_agent = ua.random()
  34. options = webdriver.ChromeOptions()
  35. mobile_emulation = {
  36. "deviceMetrics": { "width": 360, "height": 640, "pixelRatio": 3.0 },
  37. "userAgent": "Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19" }
  38. # options.add_experimental_option("mobileEmulation", mobile_emulation)
  39. options.add_argument("--no-sandbox")
  40. options.add_argument("--disable-dev-shm-usage")
  41. options.add_argument("--headless")
  42. # print(user_agent)
  43. # options.add_argument("--user-agent=" +user_agent)
  44. options.add_argument("--incognito")
  45. driver=None
  46. try:
  47. driver = webdriver.Chrome(options=options)
  48. except:
  49. # driver.quit()
  50. # os.system('pkill -f ')
  51. os.system('kill %d' % os.getpid())
  52. sys.exit()
  53. return
  54. driver.set_window_size(1400,1000)
  55. return
  56. except:
  57. import traceback
  58. traceback.print_exc()
  59. driver=None
  60. return None
  61. def run_once(url):
  62. global driver
  63. i=random.randint(0,7)
  64. if i==0 or driver is None:
  65. time.sleep(8)
  66. re_get_webdriver()
  67. if driver is None:
  68. return
  69. try:
  70. driver.get('https://meta.chuzmo.com/HxXfN9r/keelung-cityexpo')
  71. time.sleep(12)
  72. elmt=driver.find_element_by_xpath("//span[contains(text(),'Join Room')]/..")
  73. webdriver.ActionChains(driver).move_to_element(elmt).perform()
  74. webdriver.ActionChains(driver).move_to_element(elmt).click().perform()
  75. time.sleep(5)
  76. elmt=driver.find_element_by_xpath("//Button[contains(text(),'Accept')]")
  77. webdriver.ActionChains(driver).move_to_element(elmt).perform()
  78. webdriver.ActionChains(driver).move_to_element(elmt).click().perform()
  79. time.sleep(5)
  80. elmt=driver.find_element_by_xpath("//Button[contains(text(),'Enter Room')]")
  81. webdriver.ActionChains(driver).move_to_element(elmt).perform()
  82. webdriver.ActionChains(driver).move_to_element(elmt).click().perform()
  83. time.sleep(5)
  84. elmt=driver.find_element_by_xpath("//body")
  85. print(elmt)
  86. webdriver.ActionChains(driver).move_to_element(elmt).perform()
  87. webdriver.ActionChains(driver).move_to_element(elmt).click().perform()
  88. print('elmt found')
  89. # pyautogui.press('tab')
  90. # pyautogui.press('tab')
  91. # pyautogui.press('enter')
  92. # pyautogui.press('enter')
  93. i=0
  94. elmt=driver.find_element_by_xpath("//body")
  95. elmt.send_keys(Keys.ENTER)
  96. elmt.send_keys(Keys.ENTER)
  97. elmt.send_keys(Keys.ENTER)
  98. while True:
  99. webdriver.ActionChains(driver).key_down('w').key_up('w').perform()
  100. webdriver.ActionChains(driver).key_down('w').key_up('w').perform()
  101. webdriver.ActionChains(driver).key_down('w').key_up('w').perform()
  102. webdriver.ActionChains(driver).key_down('w').key_up('w').perform()
  103. webdriver.ActionChains(driver).key_down('w').key_up('w').perform()
  104. webdriver.ActionChains(driver).key_down('w').key_up('w').perform()
  105. webdriver.ActionChains(driver).key_down('w').key_up('w').perform()
  106. webdriver.ActionChains(driver).key_down('w').key_up('w').perform()
  107. webdriver.ActionChains(driver).key_down('w').key_up('w').perform()
  108. webdriver.ActionChains(driver).key_down('w').key_up('w').perform()
  109. webdriver.ActionChains(driver).key_down('w').key_up('w').perform()
  110. webdriver.ActionChains(driver).key_down('w').key_up('w').perform()
  111. i=random.randint(0,2)
  112. if i==0:
  113. webdriver.ActionChains(driver).key_down('q').key_up('q').perform()
  114. webdriver.ActionChains(driver).key_down('q').key_up('q').perform()
  115. if i==1:
  116. webdriver.ActionChains(driver).key_down('e').key_up('e').perform()
  117. webdriver.ActionChains(driver).key_down('e').key_up('e').perform()
  118. if i==2:
  119. webdriver.ActionChains(driver).key_down('w').key_up('w').perform()
  120. webdriver.ActionChains(driver).key_down('w').key_up('w').perform()
  121. # pyautogui.keyDown('w')
  122. # time.sleep(0.1)
  123. # pyautogui.keyUp('w')
  124. # pyautogui.keyDown('a')
  125. # time.sleep(0.1)
  126. # pyautogui.keyUp('a')
  127. # i+=1
  128. # i%=10
  129. # if i==0:
  130. # pyautogui.keyDown('q')
  131. # time.sleep(0.1)
  132. # pyautogui.keyUp('q')
  133. # pyautogui.keyDown('q')
  134. # time.sleep(0.1)
  135. # pyautogui.keyUp('q')
  136. # driver.quit()
  137. print("DONE!!!!")
  138. # driver.execute_script('window.open("'+url+'","_blank");')
  139. # driver.execute_script("window.scrollTo(0, window.scrollY + 400)")
  140. # time.sleep(0.5)
  141. except:
  142. traceback.print_exc()
  143. print('exception')
  144. # time.sleep(9999)
  145. lst=[]
  146. #lst=['https://www.hhh.com.tw/columns/detail/3427/index.php']
  147. #for i in range(20):
  148. while True:
  149. l='https://cmm.ai/meta'
  150. print(l)
  151. try:
  152. run_once(l)
  153. time.sleep(2)
  154. break
  155. except:
  156. traceback.print_exc()