Python 腳本未執行

邁克087

我有以下代碼:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

def message(to,message=''):
    """this a simple function to send a whatsapp message to your friends
    and group using python and selenium an automated tool to parse the HTML 
    content and to change the properties. 
    
    paramters:
    to - enter a name from your contacts it can be friend's name or a group's title.
    message - message to be deliever"""

    d = webdriver.Chrome(r'C:/Users/Miguelangel/Desktop/chromedriver.exe')
    d.get('https://web.whatsapp.com/')                  # URL to open whatsapp web
    wait = WebDriverWait(driver = d, timeout = 900)         # inscrease or decrease the timeout according to your net connection

    message += '\nthis is a system generated message'
    # additional text to with your message to identify that it is send via software
  
    name_argument = f'//span[contains(@title,\'{to}\')]'        # HTML parse code to identify your reciever
    title = wait.until(EC.presence_of_element_located((By.XPATH,name_argument)))
    title.click()                           # to open the receiver messages page in the browser

    # many a times class name or other HTML properties changes so keep a track of current class name for input box by using inspect elements
    input_path = '//div[@class="pluggable-input-body copyable-text selectable-text"][@dir="auto"][@data-tab="1"]'
    box = wait.until(EC.presence_of_element_located((By.XPATH,input_path)))

    box.send_keys(message + Keys.ENTER)

我從我的 Windows 控制台終端執行。但它什麼都不做,沒有錯誤。見下圖:

在此處輸入圖片說明

預言家

為了使這段代碼基本上運行只需刪除

def message(to,message=''):

並使此代碼平坦。
當基本的東西可以工作並且代碼變得更加複雜時,您將不得不將其拆分為函數。
message應該定義有點不同。
反而

message += '\nthis is a system generated message'

message = '\nthis is a system generated message'

還要注意to參數。
在本地定義它。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在 PutFile 之後執行 Python 腳本(Apache - NiFi)

如何同時執行 django runserver 和 python 腳本(在 cmd 中的一行)

沒有 COMMIT 事務的 Python Sqlite3 執行腳本(sql_script)

從另一個腳本運行一個 python 腳本,其中命令行參數具有可執行文件

在 Python 中與 Tkinker 執行兩個用戶交互的腳本時出現問題

有沒有辦法在必要時通過時間填充來執行具有一致執行時間的python腳本?

模塊未導入在啟動時運行 python 腳本

Python 運行與我的腳本不同的腳本

如何安排從anaconda運行的python腳本?

Python InDesign 腳本:如何運行預檢?

使用 nohup 依次運行多個 python 腳本

如何從 Python 腳本運行 nohup 命令?

如何選擇 CPU 來運行 python 腳本?

如何與始終運行的 python 腳本通信

如何從解釋器執行 raku 腳本?

在瀏覽器中執行的 PHP Bash 腳本

Google App 腳本超出最大執行限制

加載第一個腳本後如何使腳本執行

當腳本位於 shell 的 stdin 上時,apt-get 之後的 shell 腳本中的命令未正確執行

從 VS 代碼在 Python IDLE 中運行 python 腳本

將文件行讀入 xargs 以用於並行 python 腳本

在 type="module" 腳本中獲取當前正在執行的腳本元素

在數據工廠中使用 Azure Function APP 運行 Python 腳本

試圖運行我的 python 腳本沒有做任何事情

如何運行python腳本直到它結束而沒有錯誤?

對xml輸出python腳本中的單詞進行排序和計數

運行 Python/PySpark 腳本時出現環境變量錯誤

使用已導入的模塊/模塊運行 python 腳本

如何通過命令啟動屏幕並運行python腳本