Last active
January 28, 2023 04:42
-
-
Save joshuadanpeterson/07eb50573cd4e9d47e3b64d54f61c7b7 to your computer and use it in GitHub Desktop.
bookmark_movers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from selenium import webdriver | |
from selenium.webdriver.common.keys import Keys | |
# Change this variable to the text that you want to search for in the bookmark titles and URLs | |
text = "example" | |
# Change this variable to the name of the folder that you want to move the bookmarks to | |
folder_name = "New Folder" | |
# Start Chrome | |
driver = webdriver.Chrome() | |
# Go to the bookmarks manager | |
driver.get("chrome://bookmarks") | |
# Find the bookmarks with the specified text in the title or the URL | |
bookmarks = driver.find_elements_by_xpath("//a[contains(@title, '" + text + "') or contains(@href, '" + text + "')]") | |
# Find the folder with the specified name | |
folder = driver.find_element_by_xpath("//*[@title='" + folder_name + "']") | |
# Move the bookmarks to the folder | |
for bookmark in bookmarks: | |
driver.execute_script("arguments[0].appendChild(arguments[1])", folder, bookmark) | |
# Close Chrome | |
driver.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment