gpt4 book ai didi

python - 在 Python Bottle 中获取用户浏览器信息

转载 作者:太空宇宙 更新时间:2023-11-04 07:09:17 25 4
gpt4 key购买 nike

我试图找出我的用户使用的是哪些浏览器,但我遇到了问题。如果我尝试阅读标题“User-Agent”,它通常会给我很多文本,但什么也没有告诉我。例如,如果我使用 Chrome 访问该网站,在“User-Agent” header 中有:

用户代理:“Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36”。

如您所见,这没有告诉我任何信息,因为提到了 Mozzila、Safari、Chrome 等。即使我访问过 Chrome。

我一直在使用的框架是 Bottle (Python)。

如有任何帮助,我们将不胜感激。

最佳答案

User-Agent: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36".

As you can see, this tells me nothing since there is mention of Mozzila, Safari, Chrome etc.. even though I visited with Chrome.

你上面的结论是错误的。 UA 会告诉您很多信息,包括网络浏览器的类型和版本。

下面的帖子解释了为什么 MozillaSafari 存在于 Chrome 的 UA 中。

History of the browser user-agent string

您可以尝试在user-agent-string-db 上手动分析它.

有一个 Python API

from uasparser2 import UASparser

uas_parser = UASparser()
# Instead of fecthing data via network every time, you can cache the db in local
# uas_parser = UASparser('/path/to/your/cache/folder', mem_cache_size=1000)
# Updating data is simple: uas_parser.updateData()


result = ua_parser.parse('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36')


# result
{'os_company': u'',
'os_company_url': u'',
'os_family': u'Linux',
'os_icon': u'linux.png',
'os_name': u'Linux',
'os_url': u'http://en.wikipedia.org/wiki/Linux',
'typ': u'Browser',
'ua_company': u'Google Inc.',
'ua_company_url': u'http://www.google.com/',
'ua_family': u'Chrome',
'ua_icon': u'chrome.png',
'ua_info_url': u'http://user-agent-string.info/list-of-ua/browser-detail?browser=Chrome',
'ua_name': u'Chrome 31.0.1650.57',
'ua_url': u'http://www.google.com/chrome'}

关于python - 在 Python Bottle 中获取用户浏览器信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20341580/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com