Как достать aria-label?
<div class="_5xu4"><i aria-label="New York, New York, profile picture" class="img _1-yc profpic" role="img" style="background:#d8dce6 url('https\3a //scontent-arn2-1.xx.fbcdn.net/v/t1.30497-1/cp0/c14.0.48.48a/p48x48/83245568_1845797888897938_3274147281632231424_n.png?_nc_cat\3d 1\26 _nc_sid\3d 12b3be\26 efg\3d eyJpIjoidCJ9\26 _nc_ohc\3d 4tVkeNlnOMMAX9P9kEF\26 _nc_ht\3d scontent-arn2-1.xx\26 oh\3d ab8d90eb6326f50989c103d1489c5bd7\26 oe\3d 5F46AC94') no-repeat center;background-size:100% 100%;-webkit-background-size:100% 100%;width:48px;height:48px;"></i></div>
residence_city = soup.find('div', '_5xu4')
residence_city = residence_city.findAll('aria-label')
Ответы (1 шт):
Автор решения: Evgeniy
→ Ссылка
У вас маленькая ошибка, поскольку aria-label лежит в теге i, его bs может не увидеть. Также на сколько я знаю find() ищет теги, а не атрибуты. Вот рабочий код:
from bs4 import BeautifulSoup
html = '<div class="_5xu4"><i aria-label="New York, New York, profile picture" class="img _1-yc profpic" role="img" style="background:#d8dce6 url("https\3a //scontent-arn2-1.xx.fbcdn.net/v/t1.30497-1/cp0/c14.0.48.48a/p48x48/83245568_1845797888897938_3274147281632231424_n.png?_nc_cat\3d 1\26 _nc_sid\3d 12b3be\26 efg\3d eyJpIjoidCJ9\26 _nc_ohc\3d 4tVkeNlnOMMAX9P9kEF\26 _nc_ht\3d scontent-arn2-1.xx\26 oh\3d ab8d90eb6326f50989c103d1489c5bd7\26 oe\3d 5F46AC94") no-repeat center;background-size:100% 100%;-webkit-background-size:100% 100%;width:48px;height:48px;"></i></div>'
soup = BeautifulSoup(html, 'lxml')
residence_city = soup.find('div', '_5xu4')
residence_city = residence_city.find('i')
print(residence_city['aria-label'])
После исполнения кода Вы получите:New York, New York, profile picture