# 豆瓣电影Top250
import requests
from bs4 import BeautifulSoup
for page in range(10):
page = page*25
url = "https://movie.douban.com/top250?start={}".format(page)
response = requests.get(url).text
bsObj = BeautifulSoup(response, 'html.parser')
div_tags = bsObj.find_all('div', {'class': 'info'})
try:
for div_tag in div_tags:
movie_name = div_tag.find('a').get_text().strip('\n').replace('\n','')
actors = div_tag.find('p').get_text().strip('\n').replace(' ','').replace('\n',' ')
rating_num = div_tag.find('div',{'class':'star'}).find_all('span')[1].get_text()
rating_people = div_tag.find('div',{'class':'star'}).find_all('span')[3].get_text()
jianjie = div_tag.find('span',{'class':'inq'}).get_text()
#print(movie_name + '\n' +actors + '\n' +rating_num + ' '+rating_people + '\n' + "简介:"+jianjie + '\n')
with open ('E:/douban250.txt','a+',encoding='utf-8') as f:
content = movie_name + '\n' +actors + '\n' +rating_num + ' '+rating_people + '\n' + "简介:"+jianjie+'\n'+'\n'
f.write(content)
except:
continue
[Python爬虫]1.豆瓣电影Top250
最新推荐文章于 2024-03-15 07:49:35 发布