python 使用记录 获得字符ascii码/Unicode number = ord(char) 由ascii/Unicode获得字符 char = chr(number) / char = unichr(number)
urllib模块 urllib.urlopen()返回一个类文件对象,它提供的方法:
read(),readline(),readlines(),fileno(),close()——与文件对象一样 info()——返回httplib.HTTPMessage对象,表示远程服务器返回的头信息 getcode()——返回HTTP状态码:200—成功返回,404网址未找到 geturl()——返回请求url urllib.quote(string[, safe]):对字符串进行编码。参数safe指定了不需要编码的字符 urllib.unquote(string) :对字符串进行解码; urllib.urlencode(query[, doseq]):将dict或者包含两个元素的元组列表转换成url参数。例如 字典{‘name’: ‘dark-bull’, ‘age’: 200}将被转换为”name=dark-bull&age=200” urllib.pathname2url(path):将本地路径转换成url路径; urllib.url2pathname(path):将url路径转换成本地路径
level4 主要是使用urllib和re m = re.compile(r’\d+‘) nextnumber = m.search(currentline).group() nexturl = ’http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=’+nextnumber currentline = urllib.urlopen(nexturl).read() 补充两点: f = urllib.urlopen(“http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=%s” % nextnumber) 取nextnumber的方法可以使用split然后取list里的-1
result:peak.html