Python 我在哪里可以访问firefox关于:支持的原始信息

Python 我在哪里可以访问firefox关于:支持的原始信息,python,firefox,Python,Firefox,有人知道我在哪里可以访问关于:支持数据,因为我只需要该页面的原始数据,而不需要打开firefox 从本页获取信息的最简单方法是使用python库os和sys 我需要这些数据来创建基于OS的当前用户代理,但不需要打开firefox并发送请求。我已经将firefox添加到path中,但我不能像在python中那样调用它,我必须指定firefox的完整路径 下面的py将自己更新为最新版本的firefox,我希望它能对某些人有所帮助: import subprocess,re from datetime

有人知道我在哪里可以访问关于:支持数据,因为我只需要该页面的原始数据,而不需要打开firefox


从本页获取信息的最简单方法是使用python库os和sys

我需要这些数据来创建基于OS的当前用户代理,但不需要打开firefox并发送请求。我已经将firefox添加到path中,但我不能像在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("."))