豆瓣电影TOP250
单个电影的信息
<div class="info">
<div class="hd">
<a href="https://movie.douban.com/subject/1292052/" class="">
<span class="title">肖申克的救赎</span>
<span class="title"> / The Shawshank Redemption</span>
<span class="other"> / 月黑高飞(港) / 刺激1995(台)</span>
</a>
<span class="playable">[可播放]</span>
</div>
<div class="bd">
<p class="">
导演: 弗兰克·德拉邦特 Frank Darabont 主演: 蒂姆·罗宾斯 Tim Robbins /...<br>
1994 / 美国 / 犯罪 剧情
</p>
<div class="star">
<span class="rating5-t"></span>
<span class="rating_num" property="v:average">9.7</span>
<span property="v:best" content="10.0"></span>
<span>2340403人评价</span>
</div>
<p class="quote">
<span class="inq">希望让人自由。</span>
</p>
</div>
一、正则表达式
- 正则用光标索引+查看源代码中搜索ctrl F
import requests
import csv
import re
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36'
}
class doubanmovieTop250():
def getSource(self,page):
url_base = 'https://movie.douban.com/top250?'
kw = {'start':str(25*page)}
wb_data = requests.get(url_base,params=kw,headers=headers).content.decode('utf-8')
return wb_data
def parseSource(self,page):
movieItemList = re.findall('.*?<li&