'How to get the Firefox profile path dynamically in Python?

data_path = "C:\\Users\\Cortex\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\5cfpvg5b.default"

Is there any way get this file path dynamically? Here,5cfpvg5b.default is not same for every computer.



Solution 1:[1]

The answer of Martin Evans does not work, when you have multiple profiles, and switched the default one. Profile0 is the first created profile, but bot the default one.

So the last line should be replaced with:

for section in profile.sections():
    if section.startswith("Install"):
        data_path = os.path.normpath(os.path.join(mozilla_profile, profile.get(section, "Default")))
        break

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 izaakstern