Embarrassing at the command line

高洛峰
Release: 2016-10-19 13:46:00
Original
1000 people have browsed it

I saw a very interesting article from the Internet. I reprinted it and you can try it.

Just go to the code

#!/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&#39;detail.*?<a.*?>(.*?)<.*?title="(.*?)">\s*(.*?)\s*?<&#39;,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 &#39;输入"q"退出程序&#39;
    print "-"*40
    qb=qiubai()
    qb.query()
Copy after login


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template