小工具,提取最新的chrome and firefox書簽鏈接
2023-09-27 14:21:05 时间
import os, sys, json
import sqlite3
import pprint,time, datetime
def flattenX(candidates):
ret = []
for candidate in candidates:
if 'children' in candidate:
ret.extend(flattenX(candidate['children']))
else:
ret.append(candidate)
return ret
def date_from_webkit(webkit_timestamp):
epoch_start = datetime.datetime(1601,1,1)
delta = datetime.timedelta(microseconds=int(webkit_timestamp))
return (epoch_start + delta) # py3 requires () for print
def listX(data):
candidates = []
for item in data['roots']:
candidates.append(data['roots'][item])
#children = data['roots'][item]['children']
children = flattenX(candidates)
print (len(children))
children = sorted(children, key=lambda x: x['date_added'], reverse=True)
#pprint.pprint(children[:10])
#print(json.dumps(children[:10], indent=4, sort_keys=True))
for i in children[:50]:
#t = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(int(i['date_added'])/1000000))
t = date_from_webkit(int(i['date_added']))
print(i['name'], i['url'], t)
def chrome():
paths = [
os.path.expanduser("~/.config/google-chrome/Default/Bookmarks"),
os.path.expanduser(
"~/Library/Application Support/Google/Chrome/Default/Bookmarks"),
os.path.expanduser(
"~\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\Bookmarks")
]
path = ""
if "linux" in sys.platform.lower():
path = "~/.config/google-chrome/Default/Bookmarks"
if "darwin" in sys.platform.lower():
path = "~/Library/Application Support/Google/Chrome/Default/Bookmarks"
if "win32" in sys.platform.lower():
path = "~\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\Bookmarks"
path = os.path.expanduser(path)
folders = []
urls = []
for f in paths:
if os.path.exists(f):
print(f)
data = json.loads(open(f, encoding='utf-8').read())
#print(json.dumps(data, indent=4, sort_keys=True))
listX(data)
# execute a query on sqlite cursor
def execute_query(cursor, query):
try:
cursor.execute(query)
except Exception as error:
print(str(error) + "\n " + query)
# get bookmarks from firefox sqlite database file and print all
def get_bookmarks(cursor):
bookmarks_query = """select url, moz_places.title, rev_host, frecency,
last_visit_date from moz_places join \
moz_bookmarks on moz_bookmarks.fk=moz_places.id where visit_count>0
and moz_places.url like 'http%'
order by dateAdded desc;"""
bookmarks_query = """select DISTINCT url, moz_places.title, rev_host, frecency,
last_visit_date, dateAdded from moz_places join
moz_bookmarks on moz_bookmarks.fk=moz_places.id
where visit_count>0
order by dateAdded desc limit 50;"""
execute_query(cursor, bookmarks_query)
for row in cursor:
[link, title, rev_host, frecency, last_visit_date, dateAdded] = row
#link = row[0]
#title = row[1]
t = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(dateAdded/1000000))
print(title, link, rev_host, frecency, last_visit_date, t )
def firefox():
path = "~\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles"
bookmarks_path = os.path.expanduser(path)
# get firefox profile
profiles = []
for i in os.listdir(bookmarks_path):
sqlite_path = '%s\\%s\\places.sqlite'%(bookmarks_path, i)
if os.path.isfile(sqlite_path):
profiles.append(sqlite_path)
firefox_connection = sqlite3.connect(sqlite_path)
cursor = firefox_connection.cursor()
get_bookmarks(cursor)
cursor.close()
firefox()
print('----------------------------')
chrome()
相关文章
- 爬虫 Http请求,urllib2获取数据,第三方库requests获取数据,BeautifulSoup处理数据,使用Chrome浏览器开发者工具显示检查网页源代码,json模块的dumps,loads,dump,load方法介绍
- [转]Kindeditor图片粘贴上传(chrome)
- chrome same-site 跨域cookie问题 开发者的终极解决办法
- Python chrome浏览器使用方法介绍
- 面试官问我Chrome浏览器的渲染原理(6000字长文)
- chrome 快捷键
- chrome 插件开发2
- chrome 浏览器的预提取资源机制导致的一个请求发送两次的问题以及ClientAbortException异常
- 《21天学通HTML+CSS+JavaScript Web开发(第7版)》——2.3 使用Google Chrome 开发者工具
- Workflow更新恢复支持Chrome
- Mac下Chrome 浏览器右键菜单需双击的问题
- AVG插件泄漏Chrome用户数据
- JavaScript深入浅出第5课:Chrome是如何成功的?
- Chrome开发者工具Debug入门
- Chrome浏览器F12开发者工具的几个小技巧总结
- Chrome 升级成最新v33 造成开发上面诸多不便,赶紧回滚v32
- 如何更专业的使用Chrome开发者工具
- 不借助工具使用chrome浏览器直接长截图,