Windows 10
Python 3.10.0
Возникла проблема с автозагрузкой сторис с инстаграм с помощью selenium. Написал код, эмулировал андроид телефон, так как в компьютерной версии сайта невозможно постить сторис, при запуске код не выдает ошибок, но история почему-то не загружается, может кто подскажет в чем проблема?
Python 3.10.0
aiofiles 0.7.0
aiogram 2.14.3
aiohttp 3.7.4.post0
anyio 3.3.1
fake-useragent 0.1.11
httpcore 0.13.6
httpx 0.19.0
huepy 1.2.1
hyperframe 6.0.1
idna 2.10
imageio 2.9.0
imageio-ffmpeg 0.4.5
iniconfig 1.1.1
instabot 0.117.0
instapy 0.6.14
mock 4.0.3
MouseInfo 0.1.3
moviepy 1.0.3
multidict 5.1.0
noise 1.2.2
numpy 1.21.2
packaging 21.0
perlin-noise 1.7
phonenumbers 8.12.32
Pillow 8.4.0
pip 21.3.1
pipenv 2021.5.29
platformdirs 2.2.0
pluggy 1.0.0
plyer 2.0.0
proglog 0.1.9
protobuf 3.18.1
py 1.10.0
pyasn1 0.4.8
PyAutoGUI 0.9.53
pycparser 2.20
pydantic 1.8.2
pydivert 2.1.0
pygame 2.0.1
PyGetWindow 0.0.9
PyMsgBox 1.0.9
pynput 1.7.1
pyOpenSSL 20.0.1
pyparsing 2.4.7
pyperclip 1.8.2
PyRect 0.1.4
PyScreeze 0.1.27
PySocks 1.7.1
pytest 6.2.5
python-dotenv 0.19.1
python-telegram-bot 13.7
PyTweening 1.0.3
pytz 2021.1
pytz-deprecation-shim 0.1.0.post0
PyYAML 6.0
random-user-agent 1.0.1
regex 2021.10.8
requests 2.26.0
requests-toolbelt 0.9.1
responses 0.14.0
rfc3986 1.5.0
schedule 1.1.0
selenium 3.141.0
selenium-wire 4.5.2
uvicorn 0.15.0
virtualenv 20.7.2
virtualenv-clone 0.5.6
webbot 0.34
webdriver-manager 3.4.2
webdriverdownloader 1.1.0.3
wget 3.2
wheel 0.36.2
win32-setctime 1.0.3
wsproto 1.0.0
yarl 1.6.3
aiogram 2.14.3
aiohttp 3.7.4.post0
anyio 3.3.1
fake-useragent 0.1.11
httpcore 0.13.6
httpx 0.19.0
huepy 1.2.1
hyperframe 6.0.1
idna 2.10
imageio 2.9.0
imageio-ffmpeg 0.4.5
iniconfig 1.1.1
instabot 0.117.0
instapy 0.6.14
mock 4.0.3
MouseInfo 0.1.3
moviepy 1.0.3
multidict 5.1.0
noise 1.2.2
numpy 1.21.2
packaging 21.0
perlin-noise 1.7
phonenumbers 8.12.32
Pillow 8.4.0
pip 21.3.1
pipenv 2021.5.29
platformdirs 2.2.0
pluggy 1.0.0
plyer 2.0.0
proglog 0.1.9
protobuf 3.18.1
py 1.10.0
pyasn1 0.4.8
PyAutoGUI 0.9.53
pycparser 2.20
pydantic 1.8.2
pydivert 2.1.0
pygame 2.0.1
PyGetWindow 0.0.9
PyMsgBox 1.0.9
pynput 1.7.1
pyOpenSSL 20.0.1
pyparsing 2.4.7
pyperclip 1.8.2
PyRect 0.1.4
PyScreeze 0.1.27
PySocks 1.7.1
pytest 6.2.5
python-dotenv 0.19.1
python-telegram-bot 13.7
PyTweening 1.0.3
pytz 2021.1
pytz-deprecation-shim 0.1.0.post0
PyYAML 6.0
random-user-agent 1.0.1
regex 2021.10.8
requests 2.26.0
requests-toolbelt 0.9.1
responses 0.14.0
rfc3986 1.5.0
schedule 1.1.0
selenium 3.141.0
selenium-wire 4.5.2
uvicorn 0.15.0
virtualenv 20.7.2
virtualenv-clone 0.5.6
webbot 0.34
webdriver-manager 3.4.2
webdriverdownloader 1.1.0.3
wget 3.2
wheel 0.36.2
win32-setctime 1.0.3
wsproto 1.0.0
yarl 1.6.3
Возникла проблема с автозагрузкой сторис с инстаграм с помощью selenium. Написал код, эмулировал андроид телефон, так как в компьютерной версии сайта невозможно постить сторис, при запуске код не выдает ошибок, но история почему-то не загружается, может кто подскажет в чем проблема?
Python:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from data import users_settings_dict, direct_users_list
import time
import random
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.chrome.options import Options
import requests
import os
import json
mobile_emulation = {
"deviceMetrics": { "width": 360, "height": 640, "pixelRatio": 3.0 },
"userAgent": "Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19" }
class InstagramBot():
def __init__(self, username, password):
self.username = username
self.password = password
options = Options()
options.add_experimental_option("mobileEmulation", mobile_emulation)
# options.add_argument("--headless")
# self.browser = webdriver.Chrome("../chromedriver/chromedriver", options=options)
self.browser = webdriver.Chrome("chromedriver/chromedriver.exe",
chrome_options=options)
# метод для закрытия браузера
def close_browser(self):
self.browser.close()
self.browser.quit()
# метод логина
def login(self):
browser = self.browser
browser.get('https://www.instagram.com')
time.sleep(random.randrange(5, 7))
login_button = browser.find_element_by_xpath("/html/body/div[1]/section/main/article/div/div/div/div[3]/button[1]")
login_button.click()
time.sleep(random.randrange(4, 13))
username_input = browser.find_element_by_name('username')
username_input.clear()
username_input.send_keys(username)
time.sleep(5)
password_input = browser.find_element_by_name('password')
password_input.clear()
password_input.send_keys(password)
time.sleep(4)
password_input.send_keys(Keys.ENTER)
time.sleep(10)
# метод проверяет по xpath существует ли элемент на странице
def xpath_exists(self, url):
browser = self.browser
try:
browser.find_element_by_xpath(url)
exist = True
except NoSuchElementException:
exist = False
return exist
def story(self, img_path = ""):
browser = self.browser
#skip "remember me" shit
dont_remember_button = browser.find_element_by_xpath("/html/body/div[1]/section/main/div/div/div/button")
dont_remember_button.click()
time.sleep(random.randrange(10, 15))
#skip "add insta to ur main screen"
dont_main_screen_button = browser.find_element_by_xpath("/html/body/div[5]/div/div/div/div[3]/button[2]")
dont_main_screen_button.click()
time.sleep(random.randrange(3, 6))
#my story button
my_story_button = browser.find_element_by_xpath("/html/body/div[1]/section/main/section/div[1]/div/div/div/div[1]/button")
my_story_button.click()
time.sleep(random.randrange(10, 12))
#click to empty space
empty_click = browser.find_element_by_xpath("/html/body")
empty_click.click()
time.sleep(5)
#img post
send_img_input = browser.find_element_by_class_name("JdY43")
send_img_input.send_keys("C:/Users/Grigory/Desktop/Selenium/chromeDriver/w2.png")
print("good")
time.sleep(random.randrange(80, 90))
# if self.xpath_exists("/html/body/div[1]/section/main/section/div[1]/div/div/div/div[1]/button"):
#my story button
# my_story_button = browser.find_element_by_xpath("/html/body/div[1]/section/main/section/div[1]/div/div/div/div[1]/button")
# my_story_button.click()
# time.sleep(random.randrange(10, 14))
#skip "download our app"
# app_skip_button = browser.find_element_by_xpath("/html/body/div[5]/div/div[2]/div/div[5]/button")
# app_skip_button.click()
# time.sleep(random.randrange(8, 15))
#delete my old story
# delete_button_1 = browser.find_element_by_xpath("/html/body/div[1]/section/div[1]/div/section/div[2]/footer/div[1]/div/div/button")
# delete_button_1.click()
# time.sleep(random.randrange(10, 15))
# delete_button_2 = browser.find_element_by_xpath("/html/body/div[5]/div/div/div/div/button[1]")
# delete_button_2.click()
# time.sleep(random.randrange(10, 15))
# delete_button_3 = browser.find_element_by_xpath("/html/body/div[5]/div/div/div/div[2]/button[1]")
# delete_button_3.click()
# time.sleep(random.randrange(10, 15))
#go back to main insta screen
# go_back_button = browser.find_element_by_xpath("time.sleep(random.randrange(10, 15))")
# go_back_button
# else:
# pass
for user, user_data in users_settings_dict.items():
username = user_data['login']
password = user_data['password']
bot = InstagramBot(username, password)
bot.login()
bot.story()