文明观犇器

· · 个人记录

大家来文明观犇吧!

优点:

缺点:

代码:

import urllib.request
import time
tag='<span class=\"am-badge am-radius lg-bg-purple\">'
s={'2333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333'}
while True:
    fal=0
    stk=0
    tot=[]
    tmptmp=[]
    for h in urllib.request.urlopen(r'https://www.luogu.com.cn/feed/all?page=1').read().decode('utf-8').split('\n'):
        #print(h)
        if h!='    .feed-comment p {' and h!='        margin-bottom: 0;' and h!='    }':
            if h.find('发表了新帖子')!=-1:
                fal=1
            if h.find('<li')!=-1:
                stk+=1
            if h.find('</li>')!=-1:
                stk-=1
                if not stk:
                    if fal==0:
                        tot.append(''.join(tmptmp))
                    else:
                        fal=0
                    tmptmp=[]
                continue
            if fal==1:
                continue
            #print(h)
            h=h.replace('&#8238;','').replace('&nbsp;','').replace(tag,'<')
            #print(h)
            a=list(h)
            tmpstr=''
            flg,tmp=0,1
            for c in a:
                if c=='<':
                    tmp=0
                if tmp:
                    tmpstr+=c
                    flg=1
                if c=='>':
                    tmp=1
            if flg:
                tmptmp.append('\t'+tmpstr+'\n')
    for t in reversed(tot):
        t=t.replace('&lt;','<').replace('&gt;','>').replace('&quot;','\"')
        if t in s:
            continue
        s.add(t)
        print('@',end='')
        for c in range(1,len(t)):
            print(t[c],end='')
        print('')
    time.sleep(8)

制作不易,转载请注明出处,谢谢!

bug修复:Tag的处理