【问题标题】:how can I use selenium in python to send direct messages in instagram?如何在 python 中使用 selenium 在 instagram 中发送直接消息?
【发布时间】:2020-04-04 14:59:50
【问题描述】:

嗨,我是一个新手,我想尝试使用 selenium 制作一个 instagram 机器人来向我的朋友发送生日消息,当我了解到要在 chrome 中发送 dms 时,我遇到了一个问题,你必须检查页面和单击移动选项,然后选择要在其上查看的移动设备,然后重新加载页面;所有这些我都不知道该怎么做。我已经搜索了答案,但没有找到任何答案。

from selenium import webdriver
from time import sleep
from secrets import pw
from secrets import username

class InstaBot:
    def __init__(self, username, pw):
        self.driver = webdriver.Chrome('D:\Movies/chromedriver.exe')
        self.username = username
        self.driver.get("https://instagram.com")
        sleep(6)
        self.driver.find_element_by_xpath('/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div[2]/div/label/input')\
            .send_keys(username)
        self.driver.find_element_by_xpath("//input[@name=\"password\"]")\
            .send_keys(pw)
        self.driver.find_element_by_xpath('//button[@type="submit"]')\
            .click()
        sleep(4)
        self.driver.find_element_by_xpath("//button[contains(text(), 'Not Now')]")\
            .click()


        #keeps window open
        while x == 1:
            sleep(10)

x = 1




InstaBot(username, pw)           

【问题讨论】:

    标签: python-3.x selenium-chromedriver instagram


    【解决方案1】:

    我宁愿选择 appium 而不是使用 selenium,在浏览器中我认为他们不允许发送直接消息。使用 appium 自动化 instagram 应用

    参考这个 https://medium.com/the-mission/how-to-automate-an-effective-instagram-bot-that-isnt-spammy-b2146a2c0b19

    https://github.com/zhehaowang/themistalkles/blob/master/README.md

    【讨论】:

      【解决方案2】:
      mobile_emulation = { "deviceName": "Nexus 5" }
          chrome_options = webdriver.ChromeOptions()
          chrome_options.add_argument ("lang = en_us")
          chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)
      

      【讨论】:

      • 欢迎来到 Stack Overflow!虽然这段代码可以解决问题,including an explanation 解决问题的方式和原因确实有助于提高帖子的质量,并可能导致更多的赞成票。请记住,您正在为将来的读者回答问题,而不仅仅是现在提问的人。请edit您的答案以添加解释并说明适用的限制和假设。 From Review
      猜你喜欢
      • 1970-01-01
      • 2023-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-24
      相关资源
      最近更新 更多