首页 > 解决方案 > performance.getEntries() 没有得到更新

问题描述

我正在尝试从流媒体网站获取所有过去网络条目的 json。这是我在哪里看到这些网络条目的屏幕截图:

在此处输入图像描述

按下播放按钮后,网站会在一段时间内加载 .acc 文件(如 .mp3),大约每 11 秒一次。我正在运行一个脚本来获取由script =. 该脚本最终在 250 个条目处停止更新,即使页面中继续加载 .acc 文件也是如此。这表现为print(current==last)最终打印True。我不知道为什么getEntries无法识别加载超过 250 的项目。帮帮我?

代码:

script = "var performance = window.performance || window.mozPerformance || window.msPerformance || window.webkitPerformance || {}; var network = performance.getEntries() || {}; return network;"
url = 'https://www.iheart.com/live/kiss-108-1097/'

options = Options()
driver = webdriver.Firefox(options=options)
driver.get(url)

last= 0
for i in range(100):
     time.sleep(11)
     current = driver.execute_script(script)
     print(current==last)
     last=current

标签: pythonseleniumselenium-webdriverwebdriver

解决方案


根据对https://stackoverflow.com/a/45859018/6158174的回答,显然“通过性能条目获取网络请求只会在页面加载时提供网络请求,并且无法轮询后续的 async/ajax 调用” 。改用BrowserMob 代理 ( https://github.com/lightbody/browsermob-proxy )


推荐阅读