Here is the code that I wrote using selenium to build instagram bot:
I wrote a function to return the list of people not accepting my request
@insta_method
def pending_req_list(self):
self.goto_url(self.pending_req_url)
WebDriverWait(self.driver, 20).until(expected_conditions.presence_of_element_located((By.XPATH, '//*[@id="react-root"]/section/main/div/article/main/section')))
while True:
try:
buttn = self.driver.find_elements_by_css_selector('#react-root > section > main > div > article > main > button')
buttn[0].click()
time.sleep(3)
except Exception:
break
Everything till here was fine but then as i continued:
name_str = self.driver.find_element_by_xpath('//*[@id="react-root"]/section/main/div/article/main/section').text
print(name_str, type(name_str))
name_list = name_str.split()
print('
', name_list)
return name_list
Sorry for indentation errors here as i couldn't rectify here. Now when printing and checking the type, everything was perfect but then when i accepted the return value by running, it returned None Type
Here is how i accepted it from another file:
all_names = bot.pending_req_list()
print(all_names)
Now it showes None type. Please assist.
NOTE: I am accessing values in another file...
The full function:
@insta_method
def pending_req_list(self):
"""
Goes to the pending requests url and copies the users' name and forms a list
"""
self.goto_url(self.pending_req_url)
WebDriverWait(self.driver, 20).until(expected_conditions.presence_of_element_located((By.XPATH, '//*[@id="react-root"]/section/main/div/article/main/section')))
while True:
try:
buttn = self.driver.find_elements_by_css_selector('#react-root > section > main > div > article > main > button')
buttn[0].click()
time.sleep(3)
except Exception:
break
name_str = self.driver.find_element_by_xpath('//*[@id="react-root"]/section/main/div/article/main/section').text
self.name_list = name_str.split()
return self.name_list
Another file accessing:
from instagram_bot import InstaBot
bot = InstaBot()
bot.login()
all_names = bot.pending_req_list()
print(all_names)
If you notice that i added self.name_list, i did it as i thought it would help but it didn't.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…