我对此代码有问题,错误在代码下方,这就是代码。请帮我解决。
# Import requiements
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
# Create our class
class InstagramBot:
def __init__(self, username, password):
self.username = username
self.password = password
self.bot = webdriver.Firefox(executable_path = '/Users/dragos/Downloads/geckodriver')
# Function will log us in to Instagram
def login(self):
bot = self.bot
# Navigate to the Instagram login page
bot.get('https://www.instagram.com/accounts/login/')
time.sleep(3)
# Find the email and password boxes, enter our login credentials
email = bot.find_element_by_name('username').send_keys(self.username)
password = bot.find_element_by_name('password').send_keys(self.password)
# Wait for 1 second then press ENTER
time.sleep(1)
bot.find_element_by_name('password').send_keys(Keys.RETURN)
# Wait 3 second while the post-login page loads
time.sleep(3)
def findMyFollowers(self, number_of_followers):
bot = self.bot
bot.get('https://instagram.com/' + self.username)
time.sleep(2)
bot.find_element_by_xpath('//a[@href="/' + self.username + '/followers/"]').click()
time.sleep(1)
popup = bot.find_element_by_class_name('isgrP')
followers_array = []
i = 1
while len(followers_array) <= number_of_followers:
bot.execute_script('arguments[0].scrollTop = arguments[0].scrollHeight', popup)
time.sleep(0.4)
followers = bot.find_elements_by_class_name('FPmhX')
for follower in followers:
if follower not in followers_array:
followers_array.append(follower.text)
i+=1
print(followers_array)
self.followers = followers_array
def followTheirFollowers(self, number_to_follow):
bot = self.bot
for follower in self.followers:
bot.get('https://instagram.com/' + follower)
time.sleep(2)
if(len(bot.find_elements_by_xpath("//*[contains(text(), 'This Account is Private')]")) > 0):
# If they're private, we can't see their follower list, so skip them
continue
bot.find_element_by_xpath('//a[@href="/' + follower + '/followers/"]').click()
time.sleep(3)
follow = bot.find_elements_by_xpath("//button[contains(text(), 'Follow')]")
i = 1
for follower in follow:
if(i != 1):
bot.execute_script("arguments[0].click();", follower)
if(i > number_to_follow):
break
i+=1
time.sleep(2)
insta = InstagramBot('Username(here I put my username)', 'Password(and here password)')
insta.login()
insta.findMyFollowers(5)
insta.followTheirFollowers(10)
这里是错误
Traceback (most recent call last):
File "/Users/dragos/Desktop/follow.py", line 93, in <module>
insta = InstagramBot('y', 'x')
File "/Users/dragos/Desktop/follow.py", line 11, in __init__
self.bot = webdriver.Firefox(executable_path = '/Users/dragos/Downloads/geckodriver')
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/selenium/webdriver/firefox/webdriver.py", line 170, in __init__
RemoteWebDriver.__init__(
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/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.9/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: newSession
我不知道如何解决,我的课需要这个,我需要这个非常快。如果你想了解更多细节,请说你想打磨什么 我使用 python 启动器运行此代码,什么时候启动 Firefox 我有这个错误,我知道如何解决