Можно ли удалить определенные вкладки из firefox (я имею в виду получение ссылок) (по номеру) из bash или чего-то еще (для удаленного использования)? [дубликат]

На этот вопрос уже есть ответ здесь:

Я хочу отправить команду через какой-нибудь api-бот мессенджера (например, бот телеграммы) и получить ответ с конкретной вкладкой (ссылка на какой-то сайт), но я не знаю, как понять эту часть об удалении вкладок firefox

Есть ли какой-нибудь не такой изощренный способ сделать это? Пожалуйста, дайте совет и извините, если это глупый вопрос. Заранее спасибо.

0
задан 1 September 2018 в 14:05

1 ответ

Можно использовать Python для выполнения этой задачи этим довольно неэлегантным решением:


#!/usr/bin/env python3

"""
Copyright (c) 2018 Helio Machado <0x2b3bfa0>

This program is free software: you can redistribute it and/or modify  
it under the terms of the GNU General Public License as published by  
the Free Software Foundation, version 3.

This program is distributed in the hope that it will be useful, but 
WITHOUT ANY WARRANTY; without even the implied warranty of 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
General Public License for more details.

You should have received a copy of the GNU General Public License 
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""

import json
from pathlib import Path
from lz4.block import decompress


def load_recovery(path):
    """
    Loads the recovery.jsonlz4 file from the path specified and
    parses the json data to a native structure. This file contains
    the current tabs of the browser.
    """
    with open(str(path), "rb") as recovery_file:
        assert recovery_file.read(8) == b"mozLz40\0"
        compressed_data = recovery_file.read()
    json_data = decompress(compressed_data)
    recovery = json.loads(json_data.decode())
    return recovery


def recovery_path():
    """
    Get the path to the recovery.jsonlz4 file.
    """
    firefox_path = Path.home() / ".mozilla" / "firefox"
    profile_path = list(firefox_path.glob("*.default"))[0]
    session_path = profile_path / "sessionstore-backups"
    return session_path / "recovery.jsonlz4"


windows = load_recovery(recovery_path())["_closedWindows"]
tabs = [tab for window in windows for tab in window["tabs"]]
urls = [tab["entries"][0]["originalURI"] for tab in tabs]

# Here you go!
print("\n".join(urls))

Лицензия: GPLv2


Это должно быть точкой хорошего начала; даже если Ваш вопрос не является столь немым, как можно предположить, я думаю, что необходимо попробовать немного тяжелее при нахождении решений и отправить результаты исследования наряду с вопросом.

Я оставлю вопрос unmaintaned и как Сообщество Wiki.

1
ответ дан 28 October 2019 в 01:25

Другие вопросы по тегам:

Похожие вопросы: