forked from liuyuzhou/python3.7sourcecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexp_movie_top.py
More file actions
29 lines (26 loc) · 1.04 KB
/
Copy pathexp_movie_top.py
File metadata and controls
29 lines (26 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from urllib import request
class MovieTop(object):
def __init__(self):
self.start = 0
self.param= '&filter='
self.headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64)'}
def get_page(self):
page_content = []
try:
while self.start <= 225:
url = 'https://movie.douban.com/top250?start=' + str(self.start)
req = request.Request(url, headers = self.headers)
response = request.urlopen(req)
page = response.read().decode('utf-8')
page_num = (self.start + 25)//25
print(f'正在抓取第{str(page_num)}页数据...' )
self.start += 25
page_content.append(page)
return page_content
except request.URLError as e:
if hasattr(e, 'reason'):
print(f'抓取失败,失败原因:{e.reason}')
def main(self):
print('开始从豆瓣电影抓取数据........')
self.get_page()
print('数据抓取完毕...')