对分享列表阅读数进行提取
发布时间:2020-05-29 00:47:32 所属栏目:Python 来源:互联网
导读:对分享列表阅读数进行提取
|
下面是脚本之家 jb51.cc 通过网络收集整理的代码片段。 脚本之家小编现在分享给大家,也给大家做个参考。 #!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date : 2015-06-01 10:30:06
# @Author : HG ([emailprotected])
# @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
以上是脚本之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。 如果觉得脚本之家网站内容还不错,欢迎将脚本之家网站推荐给程序员好友。 (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
