简体   繁体   English

如何从whatsapp聊天中获取表情符号并通过python selenium将该表情符号发送给发件人

[英]how to get emoji from whatsapp chat and and send that emoji to sender by python selenium

This is the code.这是代码。 How to get emoji from whatsapp chat and and send that emoji to sender by python selenium如何从whatsapp聊天中获取表情符号并通过python selenium将该表情符号发送给发件人

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


driver = webdriver.Chrome()
driver.get(r'https://web.whatsapp.com/')
searchbox = WebDriverWait(driver, 10).until(expected_conditions.presence_of_element_located((By.XPATH, "//div[@id='side']//div//div//label//div//div[@contenteditable='true']")))
searchbox.send_keys('ENTER YOUR CHAT NAME')
searchbox.send_keys(Keys.RETURN)
input("Enter any key :")
chats = driver.find_elements_by_class_name("message-in")
if len(chats) > 6:
    chats = chats[-6:]
for i in range(0, len(chats)): 
    try:           
        chat = chats[i].find_element_by_class_name("_24wtQ") 
        emojiclass = chats[i].find_elements_by_class_name("_3ExzF")
        emoji = driver.find_element_by_css_selector("img").get_attribute("src")
        print(emoji) 
    except Exception as e:
        print(e)

PLEASE HELP ME请帮我

There is no change in web element there if it contains text, emoji or text and emoji.如果它包含文本、表情符号或文本和表情符号,则那里的 web 元素没有变化。
It is a text message format.它是一种文本消息格式。
So you can not distinguish according to element class name or any other attribute if it contains emoji or not.所以你不能根据元素类名或任何其他属性来区分它是否包含表情符号。
All you can do is to extract (each) text message and then check if that text string contains emoji or not.您所能做的就是提取(每条)文本消息,然后检查该文本字符串是否包含表情符号。
UPD UPD
This XPath will give you all the incoming messages emojis:此 XPath 将为您提供所有传入消息的表情符号:

//div[@class='_1gL0z']//div[contains(@class,'message-in')]//span[@class='gejrB']

And this will give you the last incoming emoji in the conversation:这将为您提供对话中最后一个传入的表情符号:

(//div[@class='_1gL0z']//div[contains(@class,'message-in')]//span[@class='gejrB'])[last()]

If you have to get the entire last message in including that emoji, not just the emoji itself, try this如果您必须获得包含该表情符号的完整最后一条消息,而不仅仅是表情符号本身,请尝试此操作

(//div[@class='_1gL0z']//div[contains(@class,'message-in')]//span[@class='gejrB'])[last()]/..

or this或这个

(//div[@class='_1gL0z']//div[contains(@class,'message-in')]//span[@class='gejrB'])[last()]/../..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM