清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2015-06-01 10:30:06 # @Author : HG (hg0728@qq.com) # @Version : 1.0 import urllib2 import re import os def getHtml(url): #获取html源码 page = urllib2.urlopen(url) html = page.read() return html def urlPages(page): #翻页 url = 'http://www.oschina.net/code/list/7/python?p=' + str(page) heard={'User-Agent':'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'} request=urllib2.Request(url,headers=heard) return request def findList(html): #正则匹配列表 myItems = re.findall('<li>.*?<h3 class="code_title">.*?<a href="(.*?)" target="_blank" title="(.*?)">.*?</a>.*?</h3>.*?<p class="u">.*?<span class=\'stat\'>(.*?)回/(.*?)阅/(.*?)顶/(.*?)收藏</span>.*?</p>.*?</li>', html, re.S) return myItems for page in range(1, 30): #抓取的页数 html = getHtml(urlPages(page)) items = findList(html) for item in items: readmax = int(item[3]) if readmax > 800: #阅读数 s = item[0] + ' ' + item[1] + '\n' file_object = open('open.txt', 'a') file_object.write(s) file_object.close() else: pass