刚开始学习的时候写的代码 现在看看真是感慨

Posted cwkcwk

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了刚开始学习的时候写的代码 现在看看真是感慨相关的知识,希望对你有一定的参考价值。

from urllib import request
import json
import time
import re

url = ["https://movie.douban.com/celebrity/1032800/movies?start=0&format=pic&sortby=time&","https://movie.douban.com/celebrity/1032800/movies?start=10&format=pic&sortby=time&","https://movie.douban.com/celebrity/1032800/movies?start=20&format=pic&sortby=time&","https://movie.douban.com/celebrity/1032800/movies?start=30&format=pic&sortby=time&"]
for i in url:


url = i

rsp = request.urlopen(url)
print(type(rsp))

data = rsp.read().decode()
print(type(data))
#data = json.loads(data)
#timesleep(1)
##########print(data)

#需要提取<dt>()</div>
s = r‘<dt>(.*?)</div>‘

pattern = re.compile(s,re.S) #re.S将整个提取内容视作一整个字符串 否则第一行跳转后,就会使抓取结束

dianying = pattern.findall(data)
##########print(len(dianying))
#print(dianying)
#print("==="*50)

for dyname in dianying:
ss = r‘<img.*?alt="(.*?)"‘
pattern = re.compile(ss)
biaoti = pattern.findall(dyname)
print(biaoti)

sss = r‘<span>(.*?)</span>‘
pattern = re.compile(sss)
fenshu = pattern.findall(dyname)
print(fenshu)

sss = r‘<dd>(.*?)</dd>‘
pattern = re.compile(sss)
daoyan = pattern.findall(dyname)[0]
print("导演:",daoyan)
try:
yanyuan = pattern.findall(dyname)[1]
print("演员:",yanyuan)
except:
print("无导演")
print("-----------------------------"*8)


















































以上是关于刚开始学习的时候写的代码 现在看看真是感慨的主要内容,如果未能解决你的问题,请参考以下文章

IDE看代码,挺好

绘图学习

绘图学习

rxJava入门学习笔记

代码托管至Github

从零开始学习javajava基础语法