从网上看到一篇很有意思的文章,转载过来大家可以试一下
002pc.com认为此文章对《python 填充空值 平均命令行看糗百》说的很在理。
直接上代码吧#!/usr/bin/env python
#coding:utf-8
import urllib2
import re
class qiubai:
def __init__(self,page=1):
self.page=page
def search(self,page):
url = "http://www.qiushibaike.com/week/page/%s" % page
re_qb = re.compile(r'detail.*?(.*?)<.*?title="(.*?)">s*(.*?)s*?<',re.DOTALL)
html = urllib2.urlopen(url).read()
my_qiubai = re_qb.findall(html)
for i in range(0,19):
for k in range(3):
print my_qiubai[i][k]
s = raw_input("回车继续")
if s == "q":
exit()
else:
page=int(page)+1
print "-"*18 + "第" + str(page) + "页" + "-"*18
self.search(page)
print "-"*40
def query(self):
global p
p = raw_input("输入要看的页数:")
if p == "q":
exit()
elif not p.isdigit() or p =="0":
self.query()
else:
print "-"*18 + "第" + p + "页" + "-"*18
self.search(p)
if __name__ == "__main__":
print "-"*40
print "糗百命令行版"
print '输入"q"退出程序'
print "-"*40
qb=qiubai()
qb.query()
更多:python 填充空值 平均命令行看糗百
https://www.002pc.comhttps://www.002pc.com/python/2203.html
你可能感兴趣的命令行
No alive nodes found in your cluster
0踩
赏
0 赞
Tags:命令行