[Python爬虫]1.豆瓣电影Top250

# 豆瓣电影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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值