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

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)

转载于:https://www.cnblogs.com/cwkcwk/p/9461378.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值