使用urllib和正则抓取和分析网页的简单代码片段
import urllib, re url = 'http://www.viedemerde.fr/aleatoire' page = urllib.urlopen(url).read() parse = re.findall("\<div class=\"post article\" id=\"(.+?)\">(.+?)</div", page) for article in parse: parse1 = re.findall("\<a href=\"(.+?)" + article[0] + "\" class=\"fmllink\">(.+?)</a>", article[1]) vdm = '' for test in parse1: vdm += test[1] print("http://viedemerde.fr/"+article[0]+" : "+vdm)