楞严经

又如新霁,清旸升天,光入隙中,发明空中诸有尘相,尘质摇动,虚空寂然。————《楞严经》
意思是说雨后新晴,太阳光射入门缝,从门缝的光里可以看到空中尘土飞扬,就像你经受波折,颠沛流离。尘质轻而浮动,但虚空依然寂静博大,虽然看不见,却时刻相伴相随。

模拟链表

def ALlist():
    data=[]
    right=[]
    for i in range(1,20):
        data.append(0)
        right.append(0)
    n=int(input("请决定输入几个数:"))
    for i in range(1,n+1):
        a=input("please input:")
        data[i]=a
        if i==n:
            right[i]=0
        else:
            right[i]=i+1
    tail=n+1
    x=input("请输入待插入的数:")
    data[tail]=x
    t=1
    while(t!=0):
        if data[right[t]]>data[tail]:
            right[tail]=right[t]
            right[t]=tail
            break
        t=right[t]
    print(data)
    print(right)
    t=1
    while t!=0:
        print(data[t],end=' ')
        t=right[t]
ALlist()

爬取QQ音乐流行指数榜

import requests
import re
def Get_HTML(url):
    headers={'User-Agent':'Mozilla/5.0'}
    try:
        r=requests.get(url,headers=headers)
        r.raise_for_status()
        r.encoding=r.apparent_encoding
        return r.text
    except:
        print("error!")
def ParsePage(html):
    pattern=re.compile('<div class="songlist__songname">.?<a title="(.?)" href.?>.?</a>.?<div class="songlist__artist">.?<a class.?>(.?)</a>',re.S)
    items=re.findall(pattern,html)
    return items
def Print(items):
    name=[]
    tplt="{0:^10}{1:^25}{2:^25}"
    print("{0:^10}{1:^25}{2:^18}".format("排名","歌名","歌手",chr(12288)))
    for i in range(20):
        print(tplt.format(i+1,itemsi,itemsi),chr(12288))
def main():
    url='https://y.qq.com/n/ryqq/toplist/4';
    html=Get_HTML(url)
    items=ParsePage(html)
    Print(items)
main()

re和pyquery练习(爬取1905电影网)

正则表达式
import requests
import re
import json
from lxml import etree
from bs4 import BeautifulSoup
from pyquery import PyQuery as pq
"获取html文档"
def Get_HTML(url):
headers={'User-Agent':'Mozilla/5.0'}
try:
    r=requests.get(url,headers=headers)
    r.raise_for_status()
    r.encoding=r.apparent_encoding
    return r.text
except:
    print("Error!")
"设置正则表达式规则,获取信息"
def parse_pages(html):
pattern=re.compile('<dl.?cl">.?nob.?>(.?)</b>.?class="li03 oh".?href="(.?)".?class=" pl28">(.?)</a>.?<span>.?title=.?>(.?)</a>.?title=.?>(.?)</a>.?title=.?>(.?)</a>.?class="li05 ta_c".?<span>(.?)</span>.*?</dl>',re.S)
items=re.findall(pattern,html)
for item in items:
    yield{
        'index':item[0],
        'image':item[1],
        'title':item[2],
        'actor':item[3:6],
        'score':item[6]
        } 
def main():
url='https://www.1905.com/vod/top/lst/';
html=Get_HTML(url)
for item in parse_pages(html):
    print(item)
    #Write_to_file(item) 
main()

pyquery
from pyquery import PyQuery as pq
import requests
import re
import json

def Get_HTML(url):
    headers = {'User-Agent': 'Mozilla/5.0'}
    try:
        r = requests.get(url, headers=headers)
        r.raise_for_status()
        r.encoding = r.apparent_encoding
        return r.text
    except:
        print("Error!")

def parse_page(html):
    doc=pq(html)
    title=doc('.li03 a').text().split(' ')  #名称
    actor=doc('.li04 span').text().split(' ')  #演员表
    index=doc('.li01 b').text().split(' ')     #序号
    href=[]  #链接
    for i in doc('.li03 a').items():  #遍历
        href.append(i.attr('href'))
    score=doc('.li05 span').text().split(' ')  #评分
    Result={}
    for i in range(100):
        result={
            '序号':index[i],
            '名称':title[i],
            '链接':href[i],
            '演员':actor[i],
            '评分':score[i]
        }
        Result[index[i]]=result
    return Result
def write_to_file(item):
    with open('1905电影排行榜.txt', 'a+', encoding='UTF-8') as f:
        f.write(json.dumps(item, ensure_ascii=False) + '\n')
def main():
    url = 'https://www.1905.com/vod/top/lst/'
    html = Get_HTML(url)
    item=parse_page(html)
    for i in range(1,len(item)+1):
        write_to_file(item[str(i)])

main()