我想从给定的 HTML 代码中获取 href 属性,以便我可以进入链接并从中获取一些数据。
<div class="cb-col cb-col-67 cb-rank-plyr"> <a class="text-hvr-underline text-bold cb-font-16" href="/profiles/1643/aaron-finch" title="Aaron Finch's Profile">Aaron Finch</a> <div class="cb-font-12 text-gray">AUSTRALIA</div> </div>
<div class="cb-col cb-col-67 cb-rank-plyr"> <a class="text-hvr-underline text-bold cb-font-16" href="/profiles/10863/fakhar-zaman" title="Fakhar Zaman's Profile">Fakhar Zaman</a> <div class="cb-font-12 text-gray">PAKISTAN</div> </div>
我想获取href的属性并将其保存到列表中。
最佳答案
您可以使用正则表达式来解析 HTML 中的内容,例如 href 标记。
这里有一篇文章解释了这一点:https://medium.com/@tracy_blog/regex-and-selenium-2c5a89f23a17
关于python-3.x - 如何使用 python 的 selenium 获取 href 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52335431/