【发布时间】:2021-02-23 20:00:11
【问题描述】:
我正在考虑一个简单的 python 自动化脚本,它将在特定时间通过链接打开并进入谷歌会议。
我刚学,谁能帮帮我
【问题讨论】:
-
那么问题是什么?你试过什么?您是否正在寻找专业的开发人员来为您的问题编写代码?
标签: python python-3.x automation
我正在考虑一个简单的 python 自动化脚本,它将在特定时间通过链接打开并进入谷歌会议。
我刚学,谁能帮帮我
【问题讨论】:
标签: python python-3.x automation
我知道这不是一个很好的答案,但我也使用 google meet。我也在想同样的事情。进入我的观点,尝试使用一个名为selenium 的python 库。我每天都用它来自动化日常网络事务。
在我看来,它在 linux 上效果最好,因为 linux 有一个名为 crontab 或类似的服务..
我知道这对于 Stack Overflow 来说有点……非常规,但如果您愿意,我可以在写完代码后将代码贴在这里。我之所以说非常规,是因为这需要一些时间。
我完成了代码...比我预期的要早。暂时仅限:
我的“TODO”列表:
下面是代码,经过一些调整,它应该可以在 Windows、Mac OS 和任何其他系统上运行。我目前正在使用带有 selenium 的 Firefox...只是我的建议,但我建议您也这样做。
如果你想知道我为什么保留USE_FAILSAFE_PERCAUTIONS,那是因为每当我使用driver.implicitly_wait() 时程序都会失败。如果有人知道如何正确使用它,它会比time.sleep()更有用。
import selenium, os, time, datetime, random, warnings, sys
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
warnings.filterwarnings("ignore", category=DeprecationWarning)
print("Timestamp: " + datetime.datetime.now().strftime("%D %H:%M:%S"))
AUTOMATION_FAILED = False
USE_FAILSAFE_PERCAUTIONS = True
EMAIL_ADDRESS = ""
AD_USERNAME = None # Leave blank or put 'None' to use a regular Google account
AD_PASSWORD = ""
options = Options()
options.headless = False
profile = webdriver.FirefoxProfile()
binary = FirefoxBinary('/usr/lib/firefox-esr/firefox-esr') # Absolute path to Firefox executable
driver = webdriver.Firefox(profile, options=options, firefox_binary=binary)
driver.maximize_window()
driver.get("https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1<mpl=default<mplcache=2&emr=1&osid=1#identifier")
print("Successfully loaded Google Authetication point! [Gmail]")
time.sleep(2)
if AUTOMATION_FAILED == False:
for i in range(6):
try:
driver.find_element_by_id("identifierId").send_keys(EMAIL_ADDRESS)
driver.find_element_by_id("identifierNext").click()
print("Sucessfully uploaded email...")
break
except selenium.common.exceptions.NoSuchElementException:
print("[ERROR]: Attempting to resend email address.")
if USE_FAILSAFE_PERCAUTIONS: time.sleep(6)
else: driver.implicitly_wait(6)
except selenium.common.exceptions.WebDriverException as e:
print("[ERROR]: Web driver error.\n[ERROR DETAILS]:",e)
AUTOMATION_FAILED = True
break
if AUTOMATION_FAILED == False:
if AD_USERNAME == "" or AD_USERNAME == None:
for i in range(6):
try:
driver.find_element_by_name("password").send_keys(AD_PASSWORD)
driver.find_element_by_id("passwordNext").click()
print("Sucessfully sent credentials...")
break
except selenium.common.exceptions.NoSuchElementException:
print("[ERROR]: Attempting to find password input.")
if USE_FAILSAFE_PERCAUTIONS: time.sleep(6)
else: driver.implicitly_wait(6)
else:
for i in range(6):
try:
driver.find_element_by_id("userNameInput").send_keys(AD_USERNAME)
driver.find_element_by_id("passwordInput").send_keys(AD_PASSWORD)
driver.find_element_by_id("submitButton").click()
print("Sucessfully sent Active Directory credentials...")
break
except selenium.common.exceptions.NoSuchElementException:
print("[ERROR]: Attempting to find active directory login elements.")
if USE_FAILSAFE_PERCAUTIONS: time.sleep(6)
else: driver.implicitly_wait(6)
except selenium.common.exceptions.WebDriverException as e:
print("[ERROR]: Web driver error.\n[ERROR DETAILS]:",e)
AUTOMATION_FAILED = True
break
time.sleep(2)
print("Loading Google Meets...")
driver.get("https://meet.google.com")
driver.refresh()
我知道程序会加入它在您加载网站时找到的第一个会议,例如:如果“英语”就在“使用会议代码”按钮的正下方,程序将加入“英语”。它可以很容易地重新配置以在需要英语时加入。
该程序还可以通过按 CTRL + d 关闭您的麦克风,并通过按 CTRL + e 关闭您的相机。同样,这可以针对 Mac OS 重新配置。
import selenium, os, time, datetime, random, warnings, sys
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
warnings.filterwarnings("ignore", category=DeprecationWarning)
print("Timestamp: " + datetime.datetime.now().strftime("%D %H:%M:%S"))
AUTOMATION_FAILED = False
USE_FAILSAFE_PERCAUTIONS = True
EMAIL_ADDRESS = ""
AD_USERNAME = ""
AD_PASSWORD = ""
options = Options()
options.headless = False
profile = webdriver.FirefoxProfile()
binary = FirefoxBinary('/usr/lib/firefox-esr/firefox-esr') # Absolute path to Firefox executable
driver = webdriver.Firefox(profile, options=options, firefox_binary=binary)
driver.maximize_window()
driver.get("https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1<mpl=default<mplcache=2&emr=1&osid=1#identifier")
print("Successfully loaded Google Authetication point! [Gmail]")
time.sleep(2)
if AUTOMATION_FAILED == False:
for i in range(6):
try:
driver.find_element_by_id("identifierId").send_keys(EMAIL_ADDRESS)
driver.find_element_by_id("identifierNext").click()
print("Sucessfully uploaded email...")
break
except selenium.common.exceptions.NoSuchElementException:
print("[ERROR]: Attempting to resend email address.")
if USE_FAILSAFE_PERCAUTIONS: time.sleep(6)
else: driver.implicitly_wait(6)
except selenium.common.exceptions.WebDriverException as e:
print("[ERROR]: Web driver error.\n[ERROR DETAILS]:",e)
AUTOMATION_FAILED = True
break
if AUTOMATION_FAILED == False:
if AD_USERNAME == "" or AD_USERNAME == None:
for i in range(6):
try:
driver.find_element_by_name("password").send_keys(AD_PASSWORD)
driver.find_element_by_id("passwordNext").click()
print("Sucessfully sent credentials...")
break
except selenium.common.exceptions.NoSuchElementException:
print("[ERROR]: Attempting to find password input.")
if USE_FAILSAFE_PERCAUTIONS: time.sleep(6)
else: driver.implicitly_wait(6)
else:
for i in range(6):
try:
driver.find_element_by_id("userNameInput").send_keys(AD_USERNAME)
driver.find_element_by_id("passwordInput").send_keys(AD_PASSWORD)
driver.find_element_by_id("submitButton").click()
print("Sucessfully sent Active Directory credentials...")
break
except selenium.common.exceptions.NoSuchElementException:
print("[ERROR]: Attempting to find active directory login elements.")
if USE_FAILSAFE_PERCAUTIONS: time.sleep(6)
else: driver.implicitly_wait(6)
except selenium.common.exceptions.WebDriverException as e:
print("[ERROR]: Web driver error.\n[ERROR DETAILS]:",e)
AUTOMATION_FAILED = True
break
time.sleep(2)
print("Loading Google Meets...")
driver.get("https://meet.google.com")
#driver.refresh()
a = driver.find_elements_by_class_name("mobgod")
print(len(a))
a[0].click()
time.sleep(7) # Ensure that the browser fully loads the next part.
for i in range(6):
try:
WebDriverWait(driver, 36).until(EC.presence_of_element_located((By.XPATH, "//span[contains(text(),'Join now')]")))
time.sleep(2)
turn_off_mic_action = ActionChains(driver)
turn_off_mic_action.key_down(Keys.CONTROL).send_keys("d").key_up(Keys.CONTROL).perform();
turn_off_camera_action = ActionChains(driver)
turn_off_camera_action.key_down(Keys.CONTROL).send_keys("e").key_up(Keys.CONTROL).perform();
print("Sucessfully found landmark...turned off camera and microphone.")
break
except selenium.common.exceptions.TimeoutException:
print("[ERROR]: Attempting to find landmark...")
if USE_FAILSAFE_PERCAUTIONS: time.sleep(6)
else: driver.implicitly_wait(6)
try:
join_button = WebDriverWait(driver, 36).until(EC.presence_of_element_located((By.XPATH, "//span[contains(text(),'Join now')]")))
driver.execute_script("arguments[0].click();", join_button)
except selenium.common.exceptions.TimeoutException:
try:
join_button = WebDriverWait(driver, 36).until(EC.presence_of_element_located((By.XPATH, "//span[contains(text(),'Ask to join')]")))
driver.execute_script("arguments[0].click();", join_button)
except selenium.common.exceptions.TimeoutException:
print("Couldn't join Google Meet.")
此更新包括使用代码的功能,仅此而已。以前的版本主要依赖于拥有与 Google 的 Active Directory 服务连接的 Google 帐户。 ...在这次更新中,您现在很幸运,您可以使用您的个人帐户。
import selenium, os, time, datetime, random, warnings, sys
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
warnings.filterwarnings("ignore", category=DeprecationWarning)
print("Timestamp: " + datetime.datetime.now().strftime("%D %H:%M:%S"))
AUTOMATION_FAILED = False
USE_FAILSAFE_PERCAUTIONS = True
CLASS_CODE = ""
EMAIL_ADDRESS = ""
AD_USERNAME = ""
AD_PASSWORD = ""
options = Options()
options.headless = False
profile = webdriver.FirefoxProfile()
binary = FirefoxBinary('/usr/lib/firefox-esr/firefox-esr') # Absolute path to Firefox executable
driver = webdriver.Firefox(profile, options=options, firefox_binary=binary)
driver.maximize_window()
driver.get("https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1<mpl=default<mplcache=2&emr=1&osid=1#identifier")
print("Successfully loaded Google Authetication point! [Gmail]")
time.sleep(2)
if AUTOMATION_FAILED == False:
for i in range(6):
try:
driver.find_element_by_id("identifierId").send_keys(EMAIL_ADDRESS)
driver.find_element_by_id("identifierNext").click()
print("Sucessfully uploaded email...")
break
except selenium.common.exceptions.NoSuchElementException:
print("[ERROR]: Attempting to resend email address.")
if USE_FAILSAFE_PERCAUTIONS: time.sleep(6)
else: driver.implicitly_wait(6)
except selenium.common.exceptions.WebDriverException as e:
print("[ERROR]: Web driver error.\n[ERROR DETAILS]:",e)
AUTOMATION_FAILED = True
break
if AUTOMATION_FAILED == False:
if AD_USERNAME == "" or AD_USERNAME == None:
for i in range(6):
try:
driver.find_element_by_name("password").send_keys(AD_PASSWORD)
driver.find_element_by_id("passwordNext").click()
print("Sucessfully sent credentials...")
break
except selenium.common.exceptions.NoSuchElementException:
print("[ERROR]: Attempting to find password input.")
if USE_FAILSAFE_PERCAUTIONS: time.sleep(6)
else: driver.implicitly_wait(6)
else:
for i in range(6):
try:
driver.find_element_by_id("userNameInput").send_keys(AD_USERNAME)
driver.find_element_by_id("passwordInput").send_keys(AD_PASSWORD)
driver.find_element_by_id("submitButton").click()
print("Sucessfully sent Active Directory credentials...")
break
except selenium.common.exceptions.NoSuchElementException:
print("[ERROR]: Attempting to find active directory login elements.")
if USE_FAILSAFE_PERCAUTIONS: time.sleep(6)
else: driver.implicitly_wait(6)
except selenium.common.exceptions.WebDriverException as e:
print("[ERROR]: Web driver error.\n[ERROR DETAILS]:",e)
AUTOMATION_FAILED = True
break
time.sleep(2)
print("Loading Google Meets...")
driver.get("https://meet.google.com")
#driver.refresh()
a = driver.find_elements_by_class_name("mobgod")
print(len(a))
if len(a) != 0:
a[0].click()
if AD_USERNAME == "" or AD_USERNAME == None:
for i in range(6):
try:
driver.find_element_by_id("i3").send_keys(CLASS_CODE)
press_enter = ActionChains(driver)
press_enter.key_down(Keys.ENTER).key_up(Keys.ENTER).perform();
print("Sucessfully uploaded meeting code.")
break
except selenium.common.exceptions.NoSuchElementException:
print("[ERROR]: Attempting to upload meeting code...")
if USE_FAILSAFE_PERCAUTIONS: time.sleep(6)
else: driver.implicitly_wait(6)
time.sleep(7) # Ensure that the browser fully loads the next part.
for i in range(6):
try:
WebDriverWait(driver, 6).until(EC.presence_of_element_located((By.XPATH, "//span[contains(text(),'Join now')]")))
time.sleep(2)
turn_off_mic_action = ActionChains(driver)
turn_off_mic_action.key_down(Keys.CONTROL).send_keys("d").key_up(Keys.CONTROL).perform();
turn_off_camera_action = ActionChains(driver)
turn_off_camera_action.key_down(Keys.CONTROL).send_keys("e").key_up(Keys.CONTROL).perform();
print("Sucessfully found landmark...turned off camera and microphone.")
break
except selenium.common.exceptions.TimeoutException:
try:
WebDriverWait(driver, 6).until(EC.presence_of_element_located((By.XPATH, "//span[contains(text(),'Ask to join')]")))
time.sleep(2)
turn_off_mic_action = ActionChains(driver)
turn_off_mic_action.key_down(Keys.CONTROL).send_keys("d").key_up(Keys.CONTROL).perform();
turn_off_camera_action = ActionChains(driver)
turn_off_camera_action.key_down(Keys.CONTROL).send_keys("e").key_up(Keys.CONTROL).perform();
print("Sucessfully found landmark...turned off camera and microphone.")
break
except selenium.common.exceptions.TimeoutException:
print("[ERROR]: Attempting to find landmark...")
if USE_FAILSAFE_PERCAUTIONS: time.sleep(6)
else: driver.implicitly_wait(6)
try:
join_button = WebDriverWait(driver, 36).until(EC.presence_of_element_located((By.XPATH, "//span[contains(text(),'Join now')]")))
driver.execute_script("arguments[0].click();", join_button)
except selenium.common.exceptions.TimeoutException:
try:
join_button = WebDriverWait(driver, 36).until(EC.presence_of_element_located((By.XPATH, "//span[contains(text(),'Ask to join')]")))
driver.execute_script("arguments[0].click();", join_button)
except selenium.common.exceptions.TimeoutException:
print("Couldn't join Google Meet. Are you sure you have the right code?")
【讨论】: