教五年级小朋友们认识 python

一个简单的小爬虫

#!/usr/bin/env Python3
# -*- coding: utf-8 -*-
# @Software: PyCharm
# @virtualenv:workon
# @contact: 1040691703@qq.com
# @Desc:Code descripton
__author__ = '未昔/AngelFate'
__date__ = '2020/1/22 12:42'
import requests
import re

def sg(url):
    req = requests.get(url)
    print(req)
    if '200' in str(req):
        h5 = req.text
        cc = re.findall('<a href="/player/\d+/">.*?</a>',h5)
        if cc is not None:
            for i in cc:
                na = re.findall('class="name nowrap">(.*?)</p>',i)
                co = re.findall('class="comment nowrap">(.*?)</p>',i)
                f = re.findall('class="icon icon_like2"></i>(.*?)</span>',i)
                if len(f)>0:
                    f = f[0]
                else:
                    f = 0.0
                print(na[0],co[0],f)
        else:
            print('None')
    else:
        print('state is error and not 200')