【发布时间】:2018-04-18 01:46:12
【问题描述】:
我正在抓取一个网站,网页正在播放音频,我想知道音频何时播放完毕,所以我将事件侦听器添加到音频 webElement 以监视“onEnded”事件是否触发,我想从 driver.execute_async_script 中的 callback() 函数中得到注意。
但我总是出错
TypeError: <function MissionContentItemHelper.audio_play_end at 0x10f3b7b70> is not JSON serializable.
我的问题是:
1.arguments[arguments.length - 1] 是指 self.audio_play_end 吗?
2.为什么错误输出是关于'MissionContentItemHelper.audio_play_end is not JSON serializable'?我在 MissionContentItemHelper.audio_play_end 和 JSON 之间看不到任何线索。
3.调用audio_play_end的方式正确吗?
class MissionContentItemHelper:
def sleep(self):
audio = self.browser.find_element_by_css_selector('#audio')
self.browser.execute_async_script("""
var audio = arguments[0];
callback = arguments[arguments.length - 1];
audio.addEventListener("ended", function(_event) {
callback();
}
""", audio, self.audio_play_end)
@staticmethod
def audio_play_end():
print('the audio finished playing...')
【问题讨论】: