是否可以从 html 中提取 'title' 而不是 'class' 或 'id' 来打印鼠标悬停时出现的内容?
Is it possible to extract a 'title' instead of a 'class' or 'id' from html to print what appears when you hover over with your mouse?
问题介绍
语言版本:Python3.8
操作系统:Windows10
其他相关软件:Jupyter notebook
上下文:我一直在通过隔离 'class' 和 'id' 的 CSS 选择器来学习使用 python 和 requests_html 进行网络解析。但是,我不确定如何将 'title' 隔离为当您的鼠标悬停在某个项目上时出现的内容,例如我 account summary page.
上顶部标签旁边的数字
当我将鼠标悬停在 python 标签旁边的数字 0 上时,它说
"Asked 7 non-wiki questions with a total score of -1"
当我检查 Chrome 中的数字零时,我可以将 html 与:
隔离开来
<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>
我已经尝试过的东西:
我可以用这个接近它
>>> 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
预期结果:
Asked 7 non-wiki questions with a total score of -1.
有什么建议吗?
正如之前在 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 的评论中所解释的那样。
问题介绍
语言版本:Python3.8
操作系统:Windows10
其他相关软件:Jupyter notebook
上下文:我一直在通过隔离 'class' 和 'id' 的 CSS 选择器来学习使用 python 和 requests_html 进行网络解析。但是,我不确定如何将 'title' 隔离为当您的鼠标悬停在某个项目上时出现的内容,例如我 account summary page.
上顶部标签旁边的数字当我将鼠标悬停在 python 标签旁边的数字 0 上时,它说
"Asked 7 non-wiki questions with a total score of -1"
当我检查 Chrome 中的数字零时,我可以将 html 与:
隔离开来<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>
我已经尝试过的东西:
我可以用这个接近它
>>> 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
预期结果:
Asked 7 non-wiki questions with a total score of -1.
有什么建议吗?
正如之前在 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 的评论中所解释的那样。