Advertisement
Python253

set_baidu_default_search_engine

Mar 3rd, 2024
752
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.11 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # Filename: set_baidu_default_search_engine.py
  3. # Author: Jeoi Reqi
  4.  
  5. """
  6. Set Default Search Engine in Google Chrome
  7.  
  8. This Python script allows users to easily set their default search engine in Google Chrome to the Baidu Search Engine.
  9.  
  10. Requirements:
  11. - Python 3
  12.  
  13. Usage:
  14. 1: Ensure Python 3 is installed on your system.
  15. 2: Copy and paste the script into a Python file.
  16. 3: Customize the search engine settings within the script if desired.
  17. 4: Run the script.
  18.  
  19. The script will update your Chrome preferences, setting the Baidu Search Engine as the default.
  20.  
  21. Note: Make sure to run the script with the appropriate permissions, and modify the Chrome preferences file path if your Chrome installation directory differs.
  22. """
  23.  
  24. import os
  25. import json
  26.  
  27. # Path to the Chrome preferences file
  28. PREFS_FILE = os.path.join(os.getenv('LOCALAPPDATA'), 'Google', 'Chrome', 'User Data', 'Default', 'Preferences')
  29.  
  30. # Search engine settings to add to the Chrome preferences
  31. BAIDU_SEARCH_ENGINE = {
  32.     "default_search_provider": {
  33.         "enabled": True,
  34.         "encodings": {"query": "UTF-8", "search_url": "UTF-8"},
  35.         "favicon_url": "https://www.baidu.com/favicon.ico",
  36.         "id": "4",
  37.         "image_url": "https://www.baidu.com/img/baidu_jgylogo3.gif",
  38.         "image_url_post_params": "",
  39.         "instant_url": "",
  40.         "keyword": "baidu.com",
  41.         "name": "Baidu",
  42.         "search_url": "https://www.baidu.com/s?wd={searchTerms}",
  43.         "suggest_url": ""
  44.     }
  45. }
  46.  
  47. # Check if the Chrome preferences file exists
  48. if not os.path.isfile(PREFS_FILE):
  49.     print("Error: Chrome preferences file not found")
  50.     exit(1)
  51.  
  52. # Read current preferences from the file
  53. with open(PREFS_FILE, 'r', encoding='utf-8') as file:
  54.     preferences = json.load(file)
  55.  
  56. # Update preferences with Baidu as a search engine
  57. preferences.update(BAIDU_SEARCH_ENGINE)
  58.  
  59. # Write the updated preferences back to the file
  60. with open(PREFS_FILE, 'w', encoding='utf-8') as file:
  61.     json.dump(preferences, file, indent=2)
  62.  
  63. print("Success: Baidu has been added as a search engine in Google Chrome with ID 4")
  64.  
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement