【发布时间】:2019-05-05 12:20:33
【问题描述】:
我使用 Python 和 Selenium。 任务是点击带有 text '+like' 的按钮或带有 class 的列 'td' em>='个人资料图片'。 但是按钮没有 id,它的 class 'more-likes' 用于其他按钮。 div 与 class 'profile-image-button' (在其他 'divs' 中使用 div 的类 ID)的情况相同。 我试图获取 'td' 的 id:
button = photos.find('td', class_='profile-image')
print(button.get_id)
输出为“无”
这是网页的html代码:
<div id="category7515692" class="category-content" data-content="present" data-collapsing="true">
<table class="pictures" data-columns-count="12" data-type="gallery">
<tbody class="" data-selec="7565904" data-name="beauty" data-live="true">
<tr data-mutable-id="MR1main" class="header">
<td class="main-row-buttons" rowspan="1" data-mutable-id="Bmain">
<table>
<tbody>
<tr>
<td class="profile-image" id="view-75634" data-event-more-view="event-more-view" data-selec="7565904" islive="true" isseparatedbutton="false">
<div class="profile-image-button">
<span class="more-likes">+like</span>
</div>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
如何点击按钮或如何获取id?
【问题讨论】:
-
请提供一个更好的例子,一个不可能的真实例子,以便我们测试它。
-
我添加了很大一部分 html 代码。希望对我们有帮助
标签: python selenium beautifulsoup webdriverwait mechanicalsoup