如何使用Flask获取用户代理? [英] How do I get the user agent with Flask?

查看:152
本文介绍了如何使用Flask获取用户代理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用Flask访问用户代理,但是我找不到文档,或者没有告诉我。

解决方案

  from flask import request 
request.headers.get c>

您也可以使用 request.user_agent 对象,它包含基于useragent字符串创建的以下属性:

<

  • 平台(windows,linux,macos等)
  • 浏览器(chrome,firefox,msie等)

  • 版本

  • 语言

  • 字符串( == request.headers.get('User-Agent')


  • I'm trying to get access to the user agent with Flask, but I either can't find the documentation on it, or it doesn't tell me.

    解决方案

    from flask import request
    request.headers.get('User-Agent')
    

    You can also use the request.user_agent object which contains the following attributes which are created based on the useragent string:

    • platform (windows, linux, macos, etc.)
    • browser (chrome, firefox, msie, etc.)
    • version
    • language
    • string (== request.headers.get('User-Agent'))

    这篇关于如何使用Flask获取用户代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆