🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
~~~ more h.txt Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Charset:GBK,utf-8;q=0.7,*;q=0.3 Accept-Encoding:gzip,deflate,sdch Accept-Language:zh-CN,zh;q=0.8 Cache-Control:max-age=0 Connection:keep-alive Content-Length:120 Content-Type:application/x-www-form-urlencoded Cookie:pgv_pvi=9261867008; YWP_VOLUME=0.5; ywadp10001467053656=1269550541; fpc10001467053656=Za9UHhw9|2yealx8Maa|fses10001467053656=|r4bo4J4Maa|Za9UHhw9|fvis10001467053656=|8MHs1Y0YsH|8MHs1Y0YsH|8MHs1Y0YsH|1|8MHs1Y0YsH|8MHs1Y0YsH; pgv_si=s1099326464; _csrf_token=ec1a05522f7a4f48a238dd5b3668f5fb; uliweb_session_id=bc7be2628c12e013abe230b78ca017b1 Host:uliweb.cpython.org Origin:http://uliweb.cpython.org Referer:http://uliweb.cpython.org/login User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.65 Safari/537.31 ~~~ ~~~ f = open("h.txt") lines = f.readlines() f.close() headers = {} for i in lines: l = i.strip().split(':') headers[l[0]]=l[1] print headers ~~~ 或者: ~~~ buf ="""Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 Accept-Encoding:gzip,deflate,sdch Accept-Language:zh-CN,zh;q=0.8 Cache-Control:max-age=0 Connection:keep-alive Cookie:__utma=17226283.527444573.1390118279.1390118279.1390118279.1; __utmb=17226283.2.10.1390118279; __utmc=17226283; __utmz=17226283.1390118279.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); dc_tos=mzn24p; dc_session_id=-nw24qs|1; uuid_tt_dd=20996925328016542_20140119 Host:blog.csdn.net If-Modified-Since:Sun, 19 Jan 2014 07:56:40 GMT User-Agent:Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.68 Safari/537.36""" h = {} for line in buf.split("\n"): k,v = line.split(":",1) h[k] = v ~~~