【问题标题】:Sending whatsapp messages via python/JS通过 python/JS 发送 whatsapp 消息
【发布时间】:2018-08-22 01:46:43
【问题描述】:

我做了一个程序,它从 excel 中获取信息并通过 python 发送消息。 我使用 selenium 和“span”来寻找我需要的元素。

现在,WhatsApp 更改了他们的 HTML,不再有 span。

旧代码在这里:

import time
import xlrd

from selenium import webdriver

chrome_driver_binary = "D:\pycharm\chromedriver.exe"
driver = webdriver.Chrome(chrome_driver_binary)

driver.get('http://web.whatsapp.com')

file_location = "C:\Users\ErelNahum\Desktop\data.xlsx"
book = xlrd.open_workbook(file_location)
print "there is " + str(book.nsheets) + " sheets"
sheet = book.sheet_by_index(0)
cols = sheet.ncols - 1
print "the number of cols is " + str(cols)


raw_input('Enter anything after scanning QR code')


for i in range(cols):
    tel = sheet.cell_value((i+1), 0)
    tel = tel.replace("\"", "")
    print tel
    messege = sheet.cell_value((i+1), 1)
    messege = (messege +str(b+1))

    user = driver.find_element_by_xpath('//span[@title = "{}"]'.format(tel))
    user.click()

    msg_box = driver.find_element_by_class_name('_input-container')


    msg_box.send_keys(messege)
    driver.find_element_by_class_name('compose-btn-send').click()

    time.sleep(0.5)

如果您知道如何更改程序以使其正常运行,请告诉我。 我知道 Python、JS、C#,所以每种语言都很好。

谢谢你, 埃雷尔。

【问题讨论】:

  • SO 不是编码服务
  • "via python/JS",那你为什么要标记c#?此外,没有人会在这里免费为您工作。请阅读How to Ask
  • 我没有让你写我的代码。我问你是否有想法替换 HTML 中的“spans”。
  • @Erel Nahum,如果 excel 表中的号码未知且未作为联系人保存在联系人中,whatsapp 用户会发生什么情况...是否也会为此类号码打开聊天窗口...? /跨度>

标签: javascript python whatsapp


【解决方案1】:

在删除 span 标签后,检查您试图废弃的数据周围的任何标签,并相应地调整代码。

span 没有通用的替代品。您能否提供您要废弃的标记(至少是 span 标签所在的部分)

【讨论】:

  • 只有 div(s).. " msg_box = driver.find_element_by_xpath('//* [@id="main"]/footer/div[1]/div[2]/div /div[1]')" 不起作用
  • div 类 "_39LWd" 你尝试引用这个怎么样?
  • selenium.common.exceptions.WebDriverException:消息:未知错误:无法聚焦元素
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-05
  • 1970-01-01
  • 2018-09-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多