简体   繁体   English

我如何使用 selenium 在 python 中打印 instagram 回复消息

[英]how can i print instagram reply message in python using selenium

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
import time
import schedule

browser = webdriver.Chrome('/Users/badernm/Desktop/chromedriver')
browser.get('https://www.instagram.com/accounts/password/reset/')
usrname_bar = browser.find_element_by_name('cppEmailOrUsername')
username = '17pii_'
usrname_bar.send_keys(username + Keys.ENTER

i need to print the result that is ("thanks! check your email for reset link ") or ("no account with this email")我需要打印结果是(“谢谢!检查您的 email 以获取重置链接”)或(“此电子邮件没有帐户”)

You can get the element by class name.您可以通过 class 名称获取元素。 It will look something like this:它看起来像这样:

reply = browser.find_element_by_class_name("CgFia")
print(reply.text)

I re-created your program and added 4 extra lines that grab that text from the pop-up you want.我重新创建了您的程序并添加了 4 行额外的行,这些行从您想要的弹出窗口中获取该文本。 Then it prints the text to your terminal.然后它将文本打印到您的终端。 I also took out the 'schedule' library because I saw that you weren't using it in your code, but you can add it back in if you're just showing us a snippet of your program.我还取出了“计划”库,因为我看到您没有在代码中使用它,但如果您只是向我们展示您的程序片段,您可以将其重新添加。

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
import time

browser = webdriver.Chrome('/Users/badernm/Desktop/chromedriver')
browser.get('https://www.instagram.com/accounts/password/reset/')
usrname_bar = browser.find_element_by_name('cppEmailOrUsername')
username = '17pii_'
usrname_bar.send_keys(username + Keys.ENTER)
time.sleep(1)  # Wait for pop-up message
result = browser.find_element_by_xpath("html/body/div/div/div/div/p")  # Path to pop-up
print(result.text)  # Get pop-up text
browser.quit() # Quit browser process

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

相关问题 如何在python中使用硒打印工具提示消息 - How to print a tooltip message using selenium in python 如何使用 Selenium Python 打印 email 地址 - How can I print email address using Selenium Python 如何在 python 中的 Telebot API 命令后回复消息 - How can I reply to a message after a command in Telebot API in python Python:我如何使用Selenium打印所有源代码 - Python: how i can print all the source code by using Selenium 如何使用 Python 和 Selenium 对 Instagram 帖子发表评论? - How can I use Python and Selenium to comment on Instagram posts? 如何使用 Selenium 和 Python 避免或最小化 Instagram 的 TimeoutException? - How can i avoid or minimise TimeoutException's from Instagram using Selenium and Python? 无法使用 selenium 回复 Instagram 评论 - Not able to reply instagram comments using selenium 我如何使用 Python 中的 Selenium 驱动程序在 Facebook 上发送消息 - How I can send a message on Facebook using Selenium Driver in Python 如何使用带有 python selenium 的电报机器人发送消息 - How I can send message using telegram bot with python selenium 如何使用 python 和 selenium 将多个图像上传到 Instagram - How do I upload multiple images to Instagram using python with selenium
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM