在python中使用selenium/chromedriver发布Instagram文章

2024-10-03 17:20:20 发布

您现在位置:Python中文网/ 问答频道 /正文

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

我已经尝试使用移动仿真模式为chromedriver取得了一些成功。我可以进入文件选择屏幕,但当我回到instagram时,它不再进行移动模拟,并锁定了用户界面(它要求旋转设备)。我包括了我目前为我正在使用的webdriver选择的选项。我还包括了我用来上传文件到故事的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()
^{pr2}$

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


Tags: 文件selfadddefusernamepasswordargumentchromedriver
1条回答
网友
1楼 · 发布于 2024-10-03 17:20:20

你可以用https://github.com/instagrambot/instapy-cli上传一篇报道。它不需要标记、标签等来完成基本工作:

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

其他可能包括:

^{pr2}$

你说

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)

相关问题 更多 >