selenium爬取豆瓣电影 保存CSV格式

selenium爬取豆瓣电影 保存CSV格式

from selenium import webdriver
import csv
from multiprocessing import Pool

fp = open("电影.csv",'a')
write = csv.writer(fp)
write.writerow(['电影名称','评分','评论人数','代表名言','电影信息'])
brower = webdriver.Chrome('C:\Program Files\Google\Chrome\Application\Chromedriver.exe')
def get(URL):
    try:
        brower.get(URL)

        title = brower.find_elements_by_css_selector('div.hd')
        pingfeng = brower.find_elements_by_css_selector('span.rating_num')
        pinglunrenshu = brower.find_elements_by_css_selector('div.star') # 评分加评论人数
        daiiaominyan = brower.find_elements_by_css_selector('span.inq')
        movieino = brower.find_elements_by_css_selector('div.bd')
        for titl,pingfen,pinglunrensh,daiiaominya,mov in zip(title,pingfeng,pinglunrenshu,daiiaominyan,movieino):
            write.writerow([titl.text,pingfen.text,pinglunrensh.text[3:],daiiaominya.text,mov.text])



    except UnicodeEncodeError:
        pass

if __name__ == '__main__':
    

    url_list = ['https://movie.douban.com/top250?start={0}&filter='.format(i*25) for i in range(10)]
    for url in url_list:
        get(url
            )
        print("爬取成功")
上一篇:PHP word导入题库


下一篇:【GDB】print 操作打印完整字符串