Python小爬虫-读取豆瓣电影名称导出csv

# -*- coding: utf-8 -*-
__author__ = 'YongCong Wu'
# @Time    : 2019/6/20 10:27
# @Email   :  : 1922878025@qq.com

from requests_html import HTMLSession
import csv

session = HTMLSession()

file = open('movies.csv', 'w', newline='')
csvwriter = csv.writer(file)
csvwriter.writerow(['名称', '年份'])

links = ['https://movie.douban.com/subject/1292052/', 'https://movie.douban.com/subject/26752088/', 'https://movie.douban.com/subject/1962665/']

for link in links:
    r = session.get(link)
    title = r.html.find('#content > h1 > span:nth-child(1)', first=True)
    year = r.html.find('#content > h1 > span.year', first=True)
    csvwriter.writerow(title.text)
    csvwriter.writerow(year.text)

file.close()

  

posted @ 2019-06-21 14:26  WrYcF  阅读(472)  评论(0编辑  收藏  举报
Live2D