Я пытаюсь подключиться к Instagram через Selenium, но я хотел бы использовать область просмотра I Phone 8. Сообщение об ошибке, которое я получаю с моим кодом, является «неожиданным отступом» и «не может быть назначено выражению ошибки» , Заранее спасибо за помощь :) Кстати, я пометил строки ошибок:)
Почему происходит непредвиденная ошибка отступа? Линии правильно структурированы ...
from time import sleep
from selenium import webdriver
class InstBot():
def __init__(self,username, pw):
self.username = username
self.pw = pw
mobile_emulation = {"deviceName": "Apple iPhone 8"}
chrome_options = webdriver.ChromeOptions() #Error Here
chrome_options.add_experimental_option("mobileEmulation", mobile_emulation) #Here
self.driver = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver', chrome_options=chrome_options) #And here
a = InstaBot('Test', 'Test')
Огромное сообщение об ошибке:
usr3:venv_bot usr3$ python3 bot.py
bot.py:12: DeprecationWarning: use options instead of chrome_options
driver = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver', chrome_options=chrome_options)
Traceback (most recent call last):
File "bot.py", line 35, in <module>
a = InstBot('test', 'test')
File "bot.py", line 12, in __init__
driver = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver', chrome_options=chrome_options)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 76, in __init__
RemoteWebDriver.__init__(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py",
line 321, in execute
self.error_handler.check_response(response)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: cannot parse capability: goog:chromeOptions
from invalid argument: cannot parse mobileEmulation
from invalid argument: 'Apple iPhone 8' must be a valid device
from unknown error: must be a valid device
Что они означают с опциями? У selenium.webdriver нет опций. Способ:)
Редактировать: Проблема решена ... По какой-то причине нет Apple Phone 8 ... Я использовал Nexus 5, и тогда все работало нормально;)