如何使用python获取默认浏览器的名称

wi3ka0sx  于 2023-01-04  发布在  Python
关注(0)|答案(1)|浏览(118)

如何在python中访问默认浏览器的前10个url历史记录?

from browser_history import get_history

outputs = get_history()

# his is a list of (datetime.datetime, url) tuples

his = outputs.histories[0:10]
for i in his:
    print(i)
print("history length",len(his))
s2j5cfk0

s2j5cfk01#

这应该能帮你找到你要找的东西。

from browser_history import get_history

# Get the browser history from the get_history function
history = get_history().histories

# Create a new list to store the unique history
unique_history = []

# Iterate over the history list
for i in history:
    # Get the URL from the current history item
    url = i[1]
    
    # Check if the URL is already in the unique_history list
    if url in unique_history:
        # If it is, skip to the next iteration
        continue
    
    # If it's not, add it to the unique_history list
    unique_history.append(url)

# Print the last 10 elements of the unique_history list
print(unique_history[-10:])

相关问题