python - 我在哪里可以从 Firefox 获取有关 :support 的原始信息

标签 python firefox

有谁知道我在哪里可以访问 about:support 数据,因为我只想从该页面获取原始数据而不打开 Firefox?

enter image description here

最佳答案

从此页面获取信息的最简单方法是通过 python 库 os 和 sys。

我需要这些数据来创建基于操作系统的当前用户代理,但无需打开 Firefox 并发送请求。我已将 Firefox 添加到路径中,但我无法像在 Python 中那样调用它,我必须指定 Firefox 的完整路径。

下面的这个py将自身更新到最新版本的firefox我希望它会对某人有所帮助:

import subprocess,re
from datetime import datetime
FIREFOX = r"C:\Program Files\Mozilla Firefox\firefox.exe"
USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:{0}.{1}) Gecko/20100101 Firefox/{0}.{1}"
VERSION = re.compile('(\d+)\.(\d+)\.(\d+)')
DATE = re.compile('DATE_CHECKED\s+=\s+"(.*?)"',re.MULTILINE|re.DOTALL)
CDEF = re.compile('DEFAULT\s*=\s*"\d+\.\d+"',re.MULTILINE|re.DOTALL)
DAYS_BEFORE_CHECK = 30
DATE_CHECKED = "2018-04-13"  # Don't change manually
DEFAULT = "59.0"  # Don't change manually


def get_user_agent():
    with open("UserAgent.py") as f:
        program_data = f.read()
        date_format = "%Y-%m-%d"
        last_date = datetime.strptime(DATE.search(program_data).group(1), date_format)
        today = datetime.strptime(datetime.now().strftime(date_format), date_format)
        days = abs(today - last_date).days
        if days >= DAYS_BEFORE_CHECK:
            rebuild1 = re.sub(DATE.search(program_data).group(1), str(datetime.now().strftime(date_format)),
                              program_data)

            x = subprocess.check_output([FIREFOX, '-v', "|", "more"])
            version_no = x.strip()
            try:
                a, b, c = VERSION.search(version_no.decode()).groups()
            except:
                raise FileNotFoundError("Check firefox path")

            rebuild2 = CDEF.sub('DEFAULT = "{0}.{1}"'.format(a, b), rebuild1)
            with open("UserAgent.py", "w") as f:
                f.write(rebuild2)

    return USER_AGENT.format(*DEFAULT.split("."))

关于python - 我在哪里可以从 Firefox 获取有关 :support 的原始信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49795554/

相关文章:

python - 如何为基于文本的 python 角色扮演游戏制作保存/加载游戏?

python - 通过 geckodriver 的 Selenium Firefox webdriver 导致错误 : Failed to start browser: entity not found

firefox - Gerrit 的 "All side by side"不会在新选项卡中打开差异

python - 将 Mergesort 用于一组未排序的单词

selenium - DesiredCapabilities 类型未定义方法 firefox()

javascript - JS 在 Chrome 中工作正常但在 FireFox 中不工作

firefox - 我可以通过Javascript在浏览器本身中检测出Tor浏览器吗?

python - tensorflow 中逻辑回归模型的系数

python - 并行填充矩阵

python - 基于两个字典在 Python 中的相似性返回 'similar score'?