我正在尝试从以下html中提取data-message-id。我最初的目标是提取包含特定文本的范围的data-message-id,然后单击star_button为其加注星标。
<div class="message_content_header">
<div class="message_content_header_left">
<a href="/team/krishnag0902" target="/team/krishnag0902" class="message_sender color_U5TPDSMQQ color_9f69e7 member member_preview_link " data-member-id="U5TPDSMQQ">krishnag0902</a>
<span class="ts_tip_float message_current_status ts_tip ts_tip_top ts_tip_multiline ts_tip_delay_150 color_U5TPDSMQQ color_9f69e7 hidden ts_tip_hidden">
<span class="ts_tip_tip ts_tip_inner_current_status">
<span class="ts_tip_multiline_inner">
</span>
</span>
</span>
<a href="/archives/C5UGEFBS9/p1498084447119862" target="new_1498118826460" class="timestamp ts_tip ts_tip_top ts_tip_float ts_tip_hidden ts_tip_multiline ts_tip_delay_300"><i class="copy_only">[</i>4:34 PM<i class="copy_only">]</i><span class="ts_tip_tip"><span class="ts_tip_multiline_inner">Yesterday at 4:34:07 PM</span></span></a>
<span class="message_star_holder">
明星这条消息
</div>
</div>
<span class="message_body">hoho<span class="constrain_triple_clicks"></span></span>
<div class="rxn_panel rxns_key_message-1498084447_119862-C5UGEFBS9"></div>
<i class="copy_only"><br></i>
<span id="msg_1498084447_119862_label" class="message_aria_label hidden">
<strong>krishnag0902</strong>.
hoho.
four thirty-four PM.
</span>
我正在使用上面跨度(message_star_holder)的代码,该代码返回None
data_mess= star_button_span.find_element_by_xpath("//button[@class=
'star ts_icon ts_icon_star_o ts_icon_inherit ts_tip_top star_message
ts_tip ts_tip_float ts_tip_hidden btn_unstyle']")
print data_mess.get_attribute("innerHTML")
print star_button_span.get_attribute("data-msg-id")
答案 0 :(得分:0)
star_button_span
没有data-msg-id
属性。 data_mess
已
print data_mess.get_attribute("data-msg-id")