Post 在 python 中使用 selenium/chromedriver 的 Instagram 快拍
Post Instagram Stories using selenium/chromedriver in python
我想创建一个接受文件夹路径并使用 python 和 chromedriver 将其所有 img 内容发布到 Instagram 用户故事的机器人(我已经有很多其他功能可以使用这个集合所以我更愿意使用这些工具来解决这个问题)。如果有人创建或发现了与我描述的内容类似的内容,请评论 link.
我已经尝试为 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()
如果有人有任何想法或任何项目,请随时发表评论。没有错误答案
您可以使用 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)
我想创建一个接受文件夹路径并使用 python 和 chromedriver 将其所有 img 内容发布到 Instagram 用户故事的机器人(我已经有很多其他功能可以使用这个集合所以我更愿意使用这些工具来解决这个问题)。如果有人创建或发现了与我描述的内容类似的内容,请评论 link.
我已经尝试为 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()
如果有人有任何想法或任何项目,请随时发表评论。没有错误答案
您可以使用 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)