【问题标题】:Post Instagram Stories using selenium/chromedriver in python在 python 中使用 selenium/chromedriver 发布 Instagram 故事
【发布时间】:2019-11-13 09:46:27
【问题描述】:

我想创建一个机器人,它接受一个文件夹路径,并使用 python 和 chromedriver 将其所有 img 内容发布到一个 instagram 用户故事(我已经有很多其他功能可以使用这个设置,所以我更愿意使用这些工具解决这个问题)。如果有人创建或发现了类似于我所描述的内容,请评论链接。

我已经尝试使用移动仿真模式为 chromedriver 使用并取得了一些成功。我能够进入文件选择屏幕,但是当我返回 instagram 时,它不再进行移动仿真并锁定 UI(它要求旋转设备)。我包括了我当前为我正在使用的网络驱动程序选择的选项。我还包括了我用来将文件上传到故事中的 def。

    def __init__ (self, username, password, actionstring, inspoaccounts, 
    inspohashtags) :
        self.username = username
        self.password = password
        self.actionString = str(actionstring)
        self.inspoAccounts = (str(inspoaccounts).split('|', 30))
        self.inspoHashtags = (str(inspohashtags).split('|', 30))
        cOptions = Options()
        cOptions.add_argument("--incognito")
        cOptions.add_argument("--start-maximized")
        cOptions.add_argument('--user-agent="Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; Microsoft; Lumia 640 XL LTE) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Mobile Safari/537.36 Edge/12.10166"')
        self.driver = webdriver.Chrome(executable_path="venv/Lib/chromedriver_win32/chromedriver.exe", options=cOptions)
        self.driver.delete_all_cookies()
    def uploadStory(self, path):
        path = self.cleanPath(path)
        actions = ActionChains(self.driver)
        element = self.driver.find_element_by_css_selector(
            '#react-root > section > main > section > div.zGtbP > div > div > div > div:nth-child(1) > button')

        #THIS IS WHERE IT ASKS ME TO ROTATE MY DEVICE

        actions.move_to_element(element)
        actions.click()
        actions.perform()
        time.sleep(random.randint(3, 6))
        autoit.win_activate("Open")
        time.sleep(random.randint(4, 6))
        autoit.control_send("Open", "Edit1", path)
        time.sleep(random.randint(3, 7))
        autoit.control_send("Open", "Edit1", "{ENTER}")
        time.sleep(random.randint(3, 6))
        self.driver.find_element_by_xpath("//*[@id=\"react-root\"]/section/footer/div/div/button").click()

如果有人有任何想法或任何项目,请随时发表评论。没有错误的答案

【问题讨论】:

    标签: python selenium selenium-chromedriver instagram bots


    【解决方案1】:

    您可以使用 https://github.com/instagrambot/instapy-cli 上传故事。它完成基本工作,没有标签、主题标签等:

    from instapy_cli import client
    with client(user, passw) as cli:
        result = cli.upload(img_path, story=True)
    

    其他可能性可能涉及:

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options 
    
    driver.set_window_size(width, height)
    

    ,

    chrome_options = Options()
    useragent = "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Mobile Safari/537.36"
    chrome_options.add_argument(f"user-agent={useragent}")
    

    ,

    chrome_options.add_experimental_option("mobileEmulation", {"deviceName":"Galaxy S5"}) #or whatever
    driver = webdriver.Chrome(options=chrome_options)
    

    【讨论】:

    • 我尝试了所有这些选项,但没有成功。如果您有任何工作,请告诉我!
    • Chrome 开发工具中的切换设备工具栏使它工作,但我无法用上面的方法重现它,也无法到达按钮。使用 .send_keys(ctrl, shift, m) 应该可以到达按钮,但由于某种原因它不起作用
    • 我刚用 instapy_cli 试了一下,效果很好,谢谢!
    • 没有问题。你会选择这个作为接受的回应吗?这是我的第一个:D
    • github.com/instagrambot/instapy-cli 不再起作用,因为 IG 更改了 API。我对 selenium 和 .send_keys(ctrl, shift, m) 有同样的问题,无法访问切换设备工具栏。有谁知道如何解决这个问题以使用 Python 和 Selenium 发布故事?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-21
    • 1970-01-01
    • 1970-01-01
    • 2017-11-08
    • 1970-01-01
    相关资源
    最近更新 更多