我使用下面的代码行来获取元素的使用时间。从输出中,我可以看到我的目标是正确的区域,并且utime属性在那里,但是我仍然收到None
的输出。我已经多次尝试重新编写data-utime
属性,以确保函数的格式正确。我错过了什么?你知道吗
代码:
timeStampBox = post.find_element_by_css_selector('.fsm.fwn.fcg')
timeStampBox = timeStampBox.find_element_by_class_name('_5pcq')
print(timeStampBox.get_attribute('innerHTML'))
print(timeStampBox.get_attribute('data-utime'))
输出:
<abbr title="Monday, September 4, 2017 at 6:11am" data-utime="1504530675" data-shorten="1" class="_5ptz"><span class="timestampContent" id="js_15">September 4 at 6:11am</span></abbr>
None
abbr
元素是timeStampBox
的innerHTML
,但data-utime
不是timeStampBox
的属性。你知道吗我是这样模仿你的情况的:
div
元素是abbr
元素的容器。我可以假装它是你的timeStampBox
元素。你知道吗识别
timeStampBox
并获取其innerHTML
。和之前一样,我得到了abbr
元素。你知道吗data-utime
是None
,因为timeStampBox
中不存在此属性。你知道吗但它在
abbr
里。你知道吗我们故事的寓意:直接搜索
abbr
。你知道吗相关问题 更多 >
编程相关推荐