直接消息 Selenium Instagram

Direct Message Selenium Instagram

相信你们都很好我正在尝试使用 selenium 检查 Instagram 直接消息部分的文本区域,但是,我尝试找到路径的尝试没有成功,我将不胜感激我能得到的任何帮助。

txt_box = bot.find_element_by_xpath('/html/body/div[1]/section/div/div[2]/div/div/div[2]/div[2]/div/div[2]/div/div/div[2]/textarea')
        txt_box.send_keys(f"Hey @{user}")  # Customize your message

我收到 运行 代码时的错误:

 txt_box = bot.find_element_by_xpath('//textarea[@placeholder="Message..."]')
Exception in thread Test 1:
Traceback (most recent call last):
  File "C:\Users\veron.000\AppData\Local\Programs\Python\Python310\lib\threading.py", line 1009, in _bootstrap_inner
    self.run()
  File "C:\Users\veron.000\AppData\Local\Programs\Python\Python310\lib\threading.py", line 946, in run
    self._target(*self._args, **self._kwargs)
  File "c:\Users\veron.000\Desktop\Eros\Instagram\Instgram Dm v1\Final\Multi_Dm.py", line 83, in test_instance
    send_msg(usrnamee)
  File "c:\Users\veron.000\Desktop\Eros\Instagram\Instgram Dm v1\Final\Multi_Dm.py", line 73, in send_msg
    txt_box.send_keys(f"Hey @{user}, I'm Jordan from ARICCI’s Talent Recruitment in London.\nWe’re an upcoming sunglasses brand and we would love to see you in our new pieces!\n\nWould you be down for promoting us and earning FREE products, BIG commissions, and getting featured on our official Instagram page?\n\n DM us @ariccirecruiter to get started! Offer runs out in 48 hours. ⏳")  # Customize your message
  File "C:\Users\veron.000\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webelement.py", line 540, in send_keys
    self._execute(Command.SEND_KEYS_TO_ELEMENT,
  File "C:\Users\veron.000\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webelement.py", line 710, in _execute
    return self._parent.execute(command, params)
  File "C:\Users\veron.000\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 425, in execute

完整的错误信息显示,找到textarea没有问题。
只有 warning 在下一个版本中你将不得不使用 find_element(By.XPATH).

真正的问题使得send_key()。发送一些字符似乎有问题。
发送 emoji 可能有问题 - 所以请尝试不使用 emoji.