#coding:utf-8 import requests,bs4,sys #防止 编码问题 reload(sys) sys.setdefaultencoding('utf8') for i in range(1,30000): res = requests.get('http://www.yangtuobaobei.cn/?'+str(i)) userFile = open('userNew.txt', 'a') if(res.status_code == 200): myHTML = bs4.BeautifulSoup(res.text,"lxml") myUser = myHTML.select('.mt') if(len(myUser)>=1): print str(i) + "---" + myUser[0].getText() myStr = myUser[0].getText() userFile.write(myStr) else: print "无法找到该网页"
0则评论给“python 采集的另一种方式(速度更快)”