当前位置:   article > 正文

记录一次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
  • 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
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41

保存数据:csv

if __name__ == '__main__':
    with open('movies.csv','a',encoding='utf-8',newline=
  • 1
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Li_阴宅/article/detail/772789
推荐阅读
相关标签
  

闽ICP备14008679号