123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- #import redis
- import time
- import traceback
- #import json
- from selenium import webdriver
- from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
- import time
- import os
- from selenium.webdriver.common.keys import Keys
- from selenium.webdriver.support.ui import WebDriverWait
- from selenium.webdriver.common.by import By
- from selenium.webdriver.support import expected_conditions as EC
- import random
- import time
- import sys
- import codecs
- import random
- import os
- import time
- #import pyautogui
- driver=None
- def re_get_webdriver():
- global driver
- result=[]
- if driver is not None:
- print('closing....')
- driver.quit()
- os.system('killall chrome')
- print('quit....')
- driver=None
- try:
- # ua = userAgents()
- # user_agent = ua.random()
- options = webdriver.ChromeOptions()
- mobile_emulation = {
- "deviceMetrics": { "width": 360, "height": 640, "pixelRatio": 3.0 },
- "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" }
- # options.add_experimental_option("mobileEmulation", mobile_emulation)
- options.add_argument("--no-sandbox")
- options.add_argument("--disable-dev-shm-usage")
- options.add_argument("--headless")
- # print(user_agent)
- # options.add_argument("--user-agent=" +user_agent)
- options.add_argument("--incognito")
- driver=None
- try:
- driver = webdriver.Chrome(options=options)
- except:
- # driver.quit()
- # os.system('pkill -f ')
- os.system('kill %d' % os.getpid())
- sys.exit()
- return
- driver.set_window_size(1400,1000)
- return
- except:
- import traceback
- traceback.print_exc()
- driver=None
- return None
- def run_once(url):
- global driver
- i=random.randint(0,7)
- if i==0 or driver is None:
- time.sleep(8)
- re_get_webdriver()
- if driver is None:
- return
- try:
- driver.get('https://meta.chuzmo.com/HxXfN9r/keelung-cityexpo')
- time.sleep(12)
- elmt=driver.find_element_by_xpath("//span[contains(text(),'Join Room')]/..")
- webdriver.ActionChains(driver).move_to_element(elmt).perform()
- webdriver.ActionChains(driver).move_to_element(elmt).click().perform()
- time.sleep(5)
- elmt=driver.find_element_by_xpath("//Button[contains(text(),'Accept')]")
- webdriver.ActionChains(driver).move_to_element(elmt).perform()
- webdriver.ActionChains(driver).move_to_element(elmt).click().perform()
- time.sleep(5)
- elmt=driver.find_element_by_xpath("//Button[contains(text(),'Enter Room')]")
- webdriver.ActionChains(driver).move_to_element(elmt).perform()
- webdriver.ActionChains(driver).move_to_element(elmt).click().perform()
- time.sleep(5)
- elmt=driver.find_element_by_xpath("//body")
- print(elmt)
- webdriver.ActionChains(driver).move_to_element(elmt).perform()
- webdriver.ActionChains(driver).move_to_element(elmt).click().perform()
- print('elmt found')
- # pyautogui.press('tab')
- # pyautogui.press('tab')
- # pyautogui.press('enter')
- # pyautogui.press('enter')
- i=0
- elmt=driver.find_element_by_xpath("//body")
- elmt.send_keys(Keys.ENTER)
- elmt.send_keys(Keys.ENTER)
- elmt.send_keys(Keys.ENTER)
- while True:
- webdriver.ActionChains(driver).key_down('w').key_up('w').perform()
- webdriver.ActionChains(driver).key_down('w').key_up('w').perform()
- webdriver.ActionChains(driver).key_down('w').key_up('w').perform()
- webdriver.ActionChains(driver).key_down('w').key_up('w').perform()
- webdriver.ActionChains(driver).key_down('w').key_up('w').perform()
- webdriver.ActionChains(driver).key_down('w').key_up('w').perform()
- webdriver.ActionChains(driver).key_down('w').key_up('w').perform()
- webdriver.ActionChains(driver).key_down('w').key_up('w').perform()
- webdriver.ActionChains(driver).key_down('w').key_up('w').perform()
- webdriver.ActionChains(driver).key_down('w').key_up('w').perform()
- webdriver.ActionChains(driver).key_down('w').key_up('w').perform()
- webdriver.ActionChains(driver).key_down('w').key_up('w').perform()
- i=random.randint(0,2)
- if i==0:
- webdriver.ActionChains(driver).key_down('q').key_up('q').perform()
- webdriver.ActionChains(driver).key_down('q').key_up('q').perform()
- if i==1:
- webdriver.ActionChains(driver).key_down('e').key_up('e').perform()
- webdriver.ActionChains(driver).key_down('e').key_up('e').perform()
- if i==2:
- webdriver.ActionChains(driver).key_down('w').key_up('w').perform()
- webdriver.ActionChains(driver).key_down('w').key_up('w').perform()
- # pyautogui.keyDown('w')
- # time.sleep(0.1)
- # pyautogui.keyUp('w')
- # pyautogui.keyDown('a')
- # time.sleep(0.1)
- # pyautogui.keyUp('a')
- # i+=1
- # i%=10
- # if i==0:
- # pyautogui.keyDown('q')
- # time.sleep(0.1)
- # pyautogui.keyUp('q')
- # pyautogui.keyDown('q')
- # time.sleep(0.1)
- # pyautogui.keyUp('q')
- # driver.quit()
- print("DONE!!!!")
- # driver.execute_script('window.open("'+url+'","_blank");')
- # driver.execute_script("window.scrollTo(0, window.scrollY + 400)")
- # time.sleep(0.5)
- except:
- traceback.print_exc()
- print('exception')
- # time.sleep(9999)
- lst=[]
- #lst=['https://www.hhh.com.tw/columns/detail/3427/index.php']
- #for i in range(20):
- while True:
- l='https://cmm.ai/meta'
- print(l)
- try:
- run_once(l)
- time.sleep(2)
- break
- except:
- traceback.print_exc()
|