从字符串或字典分析标题
parserheader的Python项目详细描述
从字符串或字典中分析标题
示例
它看起来像什么下面是一个简单的parserheader程序的示例:
importparserheader...defsetHeaders():ph=parserheader.parserheader()header_str=""" POST /upload/ HTTP/1.1 Host: magnet2torrent.com Connection: keep-alive Content-Length: 1220 Cache-Control: max-age=0 Origin: http://magnet2torrent.com Upgrade-Insecure-Requests: 1 Content-Type: application/x-www-form-urlencoded User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3 Referer: http://magnet2torrent.com/ Accept-Encoding: gzip, deflate Accept-Language: en-US,en;q=0.9,id;q=0.8 Cookie: PHPSESSID=41a0f0ac4545d3f5ba9a4ba415b777e9 """headers=ph.parserHeader(header_str)print("headers =",headers)returnheaderssetHeaders()
跑步时的样子:
$ python test.py headers = {'Origin': 'http://magnet2torrent.com', 'Content-Length': '1220', 'Accept-Language': 'en-US,en;q=0.9,id;q=0.8', 'Accept-Encoding': 'gzip, deflate', 'Connection': 'keep-alive', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36', 'Host': 'magnet2torrent.com', 'Referer': 'http://magnet2torrent.com/', 'Cache-Control': 'max-age=0', 'Cookie': 'PHPSESSID=41a0f0ac4545d3f5ba9a4ba415b777e9', 'Upgrade-Insecure-Requests': '1', 'Content-Type': 'application/x-www-form-urlencoded'}
支架
- python 2.7+,python 3.x
- Windows、Linux