- 帖子
- 2
- 精华
- 0
- 积分
- 27
- 阅读权限
- 10
- 注册时间
- 2016-10-7
- 最后登录
- 2018-9-9
|
import urllib.request
from bs4 import BeautifulSoup
print('豆瓣正在热映: ')
url='http://movie.douban.com'
html=urllib.request.urlopen(url).read().decode('utf-8')
soup=BeautifulSoup(html,'html.parser')
div_hot=soup.find('div',id='screening')
div_hot=div_hot.find('ul',class_='ui-slide-content')
iterator=div_hot.find_all('li',class_='ui-slide-item')
result='豆瓣热播电影榜单\n\n\n'
list=[]
for item in iterator:
movie_title=item['data-title'].strip()
movie_release=item['data-release'].strip()
movie_rate=item['data-rate'].strip()
movie_star=item['data-star'].strip()
movie_duration=item['data-duration'].strip()
movie_actors=item['data-actors'].strip()
movie_rater=item['data-rater'].strip()
movie_region=item['data-region'].strip()
movie_director=item['data-director'].strip()
result+=movie_title+'\n'
list.append('上映年份:%s'%movie_release)
list.append('推荐星级:%d颗星'%int(eval(movie_star)/10))
list.append('评分:%s'%movie_rate)
list.append('参与评分人数:%s人'%movie_rater)
list.append('片长:%s'%movie_duration)
list.append('导演:%s'%movie_director)
list.append('主演:%s'%movie_actors)
list.append('上映地区: %s'%movie_region)
result+=' '+'\n '.join(list)
result+='\n\n------------------分界线-------------------\n\n'
list=[]
print(movie_title)
f=open('screening.txt','w')
f.write(result)
f.close()
|
|