0

Не могу понять что не так...

followers_button = browser.find_element_by_xpath("/html/body/div[1]/section/main/div/header/section/ul/li[2]/a/span").get_property('title')
            followers_count = followers_button.text
            followers_count = int(followers_count.split(' ')[0])
            print(f"Количество подписчиков: {followers_count}")
            time.sleep(2)

Ошибка

  File "C:\python\Instabot\instabot1.py", line 121, in <module>
    mybot.get_all_followers()
  File "C:\python\Instabot\instabot1.py", line 77, in get_all_followers
    followers_count = followers_button.text
AttributeError: 'str' object has no attribute 'text'
2
  • вы в тайтле ссылки, который является строкой, хотите найти текст... что не понятно в тексте ошибки?
    – Jack_oS
    28 фев 2021 в 22:06
  • Я новичок, поэтому немного не понимаю( в строке содержится текст, а конкретней количество подписчиков - цифра. Как мне извлечь эту информацию для дальнейшей операции...?
    – Alexeevich
    28 фев 2021 в 22:29

1 ответ 1

0

Полагаю что так:

followers_button = browser.find_element_by_xpath("/html/body/div[1]/section/main/div/header/section/ul/li[2]/a/span").get_property('title')
            followers_count = int(followers_count.split(' ')[0])
            print(f"Количество подписчиков: {followers_count}")
            time.sleep(2)

Либо вот так:

followers_button = browser.find_element_by_xpath("/html/body/div[1]/section/main/div/header/section/ul/li[2]/a/span")
            followers_count = followers_button.text
            followers_count = int(followers_count.split(' ')[0])
            print(f"Количество подписчиков: {followers_count}")
            time.sleep(2)

Все зависит от того какой элемент вы брали.

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.