Problem Introduction
Language version: Python 3.8
Operating system: Windows 10
Other relevant Software: Jupyter notebook
Context: I have been learning about web parsing using python and requests_html by isolating CSS selectors for 'class' and 'id'. However, I am not sure how I would isolate 'title' for something that appears when your mouse hovers over an item such as the number next to the top tag on my account summary page.
When I hover over the number 0 next to the python tag its says
"Asked 7 non-wiki questions with a total score of -1"
When I inspect the number zero in Chrome, I can isolate the html from:
<div class="answer-votes" title="Asked 7 non-wiki questions with a total score of -1. " onclick="window.location.href='/search?q=user:14340924+[python]'">0</div>
Things I have already tried:
I can get really close to it with this
>>> r.html.find('#user-panel-tags')[0].find('.user-tags')[0].find('.answer-votes')[0].text
0
r.html.find('#user-panel-tags')[0].find('.user-tags')[0].find('.answer-votes')[0].find('.title')[0].text
r.html.find('#user-panel-tags')[0].find('.user-tags')[0].find('.answer-votes title')[0].text
Expected outcome:
Asked 7 non-wiki questions with a total score of -1.
Any advice?
As previously explained in the comments by Stack, it is possible to use
.attrs()
to get the attributes of an element..attrs()
returns a dictionary which can be indexed using.attrs()['title']
or.attrs().get('title')
. Additional resources can be found at https://github.com/psf/requests-html.