用于分析RFC 8288“link”HTTP头的库
httplink的Python项目详细描述
用于分析RFC 8288 HTTP链接头的Python(>;=3.6)库。
fromhttplinkimportparse_link_headerresult=parse_link_header(''' <https://example.com/foo/index.html>; rel=index; foo*=UTF-8'en'b%c3%a5r, </path#frag>;rel="what ever" ''')## Target URL:print(result['index'].target)# https://example.com/foo/index.html## Set of link relations:print(result['index'].rel)# {'index'}## Decoded attribute value:print(result['index']['foo'])# bår## Raw undecoded attributes:print(result['index'].attributes)# [('rel', 'index'), ('foo*', "UTF-8'en'b%c3%a5r")]## Iterate over all links:forlinkinresult.links:print(link.rel,link.target)# {'index'} https://example.com/foo/index.html# {'ever', 'what'} /path#frag
如果将多个链接头与,连接,则可以同时分析它们。
多余的空格和逗号分隔符将被忽略。
["key"]-访问始终不区分大小写。