python - Python sort links by latency
问题描述
I have a list of links for eg:
['google.com','facebook.com','instagram.com']
I wanna sort the links by their latency. Is there any way i can ping the website and check latency?
If it's a video playing link then is it possible to test the speed?
Edit: Nick's answer solves the latency for me but still looking for an answer for speed of the server
解决方案
一种方法是使用请求获取链接,然后测量经过的时间。例如:
for link in links:
duration = requests.get(link).elapsed.total_seconds()
print(link, duration)
注意:这不会测量整个页面的加载时间。例如,如果网站播放视频,则页面中不会包含实际视频,只有一个 HTML 元素告诉浏览器在哪里可以找到它。
推荐阅读
- ansible - ansible 在 2.9 版中不扩展 var,它在 2.8 中有效
- highcharts - Angular 8 highcharts 如何将自定义数据传递给 Highcharts 中的向下钻取事件
- arrays - Mongo db:查询与另一个传递数组的任何元素匹配的数组
- vb.net - 更改 CefSharp 中的默认下载文件夹
- python - 每次与 Class 对象交互时,如何更新 Class 对象的属性?
- google-sheets - 收集一个 Google 工作表中与另一工作表的列中的字符串匹配的行
- c++ - 如何为 C++ gRPC 客户端绑定网络接口
- laravel - production.ERROR:命名空间声明语句必须是第一个语句或脚本中的任何声明调用之后
- python - 在 python 中打开一个 .mat 图像文件
- python - k-means聚类后的时间序列求和