#coding:utf8 import requests,re,sys #防止 编码问题 reload(sys) sys.setdefaultencoding('utf8') for i in range(1,400000): res = requests.get('http://www.yangtuobaobei.cn/?'+str(i)) if res.status_code==200: userFile = open('user.txt','a') #多行匹配,拿到用户名 user = re.compile('<h2 class="mt">\n(.*?)</h2>', re.S) myUser= user.findall(res.text) if(len(myUser)>=1): print str(i)+"--"+myUser[0] myStr = str(i)+" -------- "+myUser[0]+"\n" userFile.write(myStr) else: print "无法找到该网页"
0则评论给“python 简单采集测试”