Sending whatsapp messages via python/JS

佐手、 提交于 2019-12-02 22:59:23

问题


I made a program which takes information from excel and sends messages via python. I used selenium and "span" for finding the element I need.

now, WhatsApp changed their HTML and there is no span anymore.

the old code is here:

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)

if you have any idea how to change the program so it will work please show me. I know Python, JS, C# so every language is fine.

Thank You, Erel.


回答1:


Check whatever tag surrounds the data you're trying to scrap after the span tag was removed, and adjust the code accordingly.

There is no general replacement for span. Can you provide the markup you're trying to scrap (at least the part where the span tag was)



来源:https://stackoverflow.com/questions/49262352/sending-whatsapp-messages-via-python-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!