0

我在玩pythonchallenge level8

我尝试直接从 url 获取 un 和 pw

text = urllib.urlopen('http://www.pythonchallenge.com/pc/def/integrity.html').read()
un_pat = re.compile('un: \'(.+)\'')
compress_un = un_pat.findall(text)[0]

但实际上un应该是这样的

un = 'BZh91AY&SYA\xaf\x82\r\x00\x00\x01\x01\x80\x02\xc0\x02\x00 \x00!\x9ah3M\x07<]\xc9\x14\xe1BA\x06\xbe\x084'

有什么简单的方法(除了自己写一个循环)将compress_un转换为un吗?python是否提供了一些库来做到这一点?谢谢

4

1 回答 1

2
>>> compress_un
'BZh91AY&SYA\\xaf\\x82\\r\\x00\\x00\\x01\\x01\\x80\\x02\\xc0\\x02\\x00 \\x00!\\x9ah3M\\x07<]\\xc9\\x14\\xe1BA\\x06\\xbe\\x084'
>>> compress_un.decode('string_escape')
'BZh91AY&SYA\xaf\x82\r\x00\x00\x01\x01\x80\x02\xc0\x02\x00 \x00!\x9ah3M\x07<]\xc9\x14\xe1BA\x06\xbe\x084'
于 2013-05-02T11:14:47.167 回答