#win python 2.7.ximport re,sys,urllib,codecsxh = urllib.urlopen(http://www.baidu.com/s?q1=123&rn=100).read().decode('utf-8') rc = re.compile(r'(?p.*?)',re.i)match = rc.finditer(xh)rcr = re.compile(r']+>',re.i)f = codecs.open(xiaohei.txt, w, utf-8)for i in rc.finditer(xh): ss = i.group(0) s1 = rcr.sub('',ss) print (s1) f.write(s1)f.close()
希望本文所述对大家的python程序设计有所帮助。