I don't know python, and I am learning through experience. I started making this as part of a script that autostarts my game. The ahk script runs this python script on a timed loop. It works good for me but other people complain that either A. They don't use Chrome, or B. That they use some other browser and it opens up a different(default) browser.
My question. Is there a way I can get the current browser that is open? Like the name(Chrome, Safari, Opera, FireFox, IE)?
I have tried a few different methods of parsing the user_agent from the header and I actually have a couple parsers that work just fine... The issue is that I can't seem to find a working method of actually getting the User_Agent on python 3.8.
Solutions that would work could include: A. A working method of getting the User_Agent string so that I can parse it for the information I need. B. Another method of detecting browser type.
The code will probably be of no help since it contains no method for getting the string, but here it is.
import time
import os
import webbrowser
import platform
user_OS = platform.system()
chrome_path_windows = 'C:/Program Files
(x86)/Google/Chrome/Application/chrome.exe %s'
chrome_path_linux = '/usr/bin/google-chrome %s'
chrome_path_mac = 'open -a /Applications/Google\ Chrome.app %s'
chrome_path = ''
roblox_link = 'https://www.roblox.com/games/'
if user_OS == 'Windows':
chrome_path = chrome_path_windows
elif user_OS == 'Linux':
chrome_path = chrome_path_linux
elif user_OS == 'Darwin':
chrome_path = chrome_path_mac
elif user_OS == 'Java':
chrome_path = chrome_path_mac
else:
webbrowser.open_new_tab(roblox_link)
os.system("start SynapseX.exe")
time.sleep(10)
webbrowser.get(chrome_path).open_new_tab(roblox_link)
ok I ended up just going another route
import time
import webbrowser
import platform
import subprocess
import os
import sys
privateServerLink = 'https://www.roblox.com/games/2414851778/TIER-20-Dungeon-Quest?privateServerLinkCode=GXVlmYh0Z7gwLPBf7H5FWk3ClTVesorY'
userBrowserC = input(str("Browser Type: chrome, opera, iexplore, firefox : "))
userSleepTime = int(input("How long do you want it to run?"))
if userBrowserC == 'opera':
userBrowserD = 'launcher.exe'
else:
userBrowserD = userBrowserC
if userBrowserC == "chrome":
taskToKill = "chrome.exe"
else:
taskToKill = "iexplore.exe"
if userBrowserC == 'chrome' and platform.system() == 'Windows':
browserPath = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
elif userBrowserC == 'chrome' and platform.system() == 'Linux':
browserPath = '/usr/bin/google-chrome %s'
elif userBrowserC == 'chrome' and platform.system() == 'Darwin' or platform.system() == 'Java':
browserPath = 'open -a /Applications/Google\ Chrome.app %s'
elif userBrowserC == 'opera' and platform.system() == 'Windows':
browserPath = 'C:/Users/'+ os.getlogin() +'/AppData/Local/Programs/Opera/launcher.exe'
elif userBrowserC == 'iexplore' and platform.system() == 'Windows':
browserPath = 'C:/Program Files/internet explorer/iexplore.exe %s'
elif userBrowserC == 'firefox' and platform.system() == 'Windows':
browserPath = 'C:/Program Files/Mozilla Firefox/firefox.exe'
else:
browserPath = ''
while 1 == 1:
subprocess.Popen('SynapseX.exe')
time.sleep(7)
webbrowser.get(browserPath).open_new_tab(privateServerLink)
time.sleep(7)
os.system('taskkill /f /im '+taskToKill)
time.sleep(userSleepTime)
How would I go about just closing whatever browser that I end up opening after like 2 or 4 seconds. The link launches a webpage that launches a program. I then want to immediately close the web browser that started it. I am lost.