简体   繁体   中英

How to open url with opera in incognito mode?

This is the code that opens opera in incognito, but I have no idea how to open URL in incognito.

import subprocess
command = '"C:\\Users\\Igor\\AppData\\Local\\Programs\\Opera\\launcher.exe" --private'
subprocess.Popen(command)` 

Could anyone help me with this? Thanks

Tested on Windows 10 Pro

If you need only to open your opera in private mode, you can use subprocess.run :

subprocess.run was added in Python 3.5 as a simplification over subprocess.Popen when you just want to execute a command and wait until it finishes, but you don't want to do anything else meanwhile.

To open URL by command line, you have to use --remote <url> parameter

So, your code can look like this:

import subprocess


def run_opera_private():
    cmd = r'C:\Users\Igor\AppData\Local\Programs\Opera\launcher.exe --private --remote <url>'
    #example cmd=r'C:\Users\karol\AppData\Local\Programs\Opera\launcher.exe --private --remote google.com'
    subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)


if __name__ == '__main__':
    run_opera_private()

If you are using python < 3.5, replace subprocess.run with subprocess.Popen

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM