如何获取使用python安装在系统中的浏览器列表? [英] how to get list of browser installed in a system using python?

查看:48
本文介绍了如何获取使用python安装在系统中的浏览器列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个脚本(以python格式)来扫描机器.(假设系统具有Linux)并检索已安装浏览器的列表.寻找实施建议.我正在使用打开链接
browser = webdriver.Firefox()
在这里,我们不得不提到Firefox在Firefox浏览器中打开链接.如果用户没有在计算机上安装Firefox(安装了Chrome)怎么办?我已经搜索过,但没有任何结果.

I would like to write a script (in python) which scans the machine.(assumption is system has Linux) and retrieve the list of browser's installed. Looking for suggestions to implement it. I am using selenium to open links
browser = webdriver.Firefox()
Here we have to mention Firefox to open link in Firefox browser. What if user don't have Firefox in machine (chrome installed)? I had already searched but haven't got any result.

P.S:如果系统具有Windows/Mac OS

P.S: If system has windows/Mac OS

推荐答案

更好的方法:使用try/except块

A better approach: use try/except block

try:
    browser = webdriver.Firefox() 
    browser.get('url')

except (IOException, Exception):
    pass

在驱动程序无法找到浏览器或启动时出现问题的情况下将提供帮助.

It will help in cases where driver is not able to find the browser or there is some problem while launching.

这篇关于如何获取使用python安装在系统中的浏览器列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆