记录一次Python爬取电影数据并可视化分析

一、获取数据

1.技术工具

IDE编辑器:vscode

发送请求:requests

解析工具:xpath

def Get_Detail(Details_Url):
    Detail_Url = Base_Url + Details_Url
    One_Detail = requests.get(url=Detail_Url, headers=Headers)
    One_Detail_Html = One_Detail.content.decode('gbk')
    Detail_Html = etree.HTML(One_Detail_Html)
    Detail_Content = Detail_Html.xpath("//div[@id='Zoom']//text()")
    Video_Name_CN,Video_Name,Video_Address,Video_Type,Video_language,Video_Date,Video_Number,Video_Time,Video_Daoyan,Video_Yanyuan_list = None,None,None,None,None,None,None,None,None,None
    for index, info in enumerate(Detail_Content):
        if info.startswith('◎译  名'):
            Video_Name_CN = info.replace('◎译  名', '').strip()
        if info.startswith('◎片  名'):
            Video_Name = info.replace('◎片  名', '').strip()
        if info.startswith('◎产  地'):
            Video_Address = info.replace('◎产  地', '').strip()
        if info.startswith('◎类  别'):
            Video_Type = info.replace('◎类  别', '').strip()
        if info.startswith('◎语  言'):
            Video_language = info.replace('◎语  言', '').strip()
        if info.startswith('◎上映日期'):
            Video_Date = info.replace('◎上映日期', '').strip()
        if info.startswith('◎豆瓣评分'):
            Video_Number = info.replace('◎豆瓣评分', '').strip()
        if info.startswith('◎片  长'):
            Video_Time = info.replace('◎片  长', '').strip()
        if info.startswith('◎导  演'):
            Video_Daoyan = info.replace('◎导  演', '').strip()
        if info.startswith('◎主  演'):
            Video_Yanyuan_list = []
            Video_Yanyuan = info.replace('◎主  演', '').strip()
            Video_Yanyuan_list.append(Video_Yanyuan)
            for x in range(index + 1, len(Detail_Content)):
                actor = Detail_Content[x].strip()
                if actor.startswith("◎"):
                    break
                Video_Yanyuan_list.append(actor)
    print(Video_Name_CN,Video_Date,Video_Time)
    f.flush()
    try:
        csvwriter.writerow((Video_Name_CN,Video_Name,Video_Address,Video_Type,Video_language,Video_Date,Video_Number,Video_Time,Video_Daoyan,Video_Yanyuan_list))
    except:
        pass

保存数据:csv

if __name__ == '__main__':
    with open('movies.csv','a',encoding='utf-8',newline=
  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值