selenium爬取豆瓣电影

#coding:utf-8
#__author__='wang'

import os,time
from selenium import webdriver

driver = webdriver.Firefox()
driver.get('https://movie.douban.com/top250')
time.sleep(3)
for x in xrange(1,11):
    print '正在获取第{}页内容'.format(x)
    for i in xrange(1,7):
        i=float(i)/7

        js = "document.documentElement.scrollTop =
 document.documentElement.scrollHeight * %f"%i
        driver.execute_script(js)
        time.sleep(3)

    li_list = driver.find_elements_by_css_selector
('ol[class="grid_view"] li')

    for x in li_list:
        num = x.find_element_by_css_selector('.pic em').text
        name = x.find_element_by_css_selector('.hd a')
.text.strip().encode('utf-8')
        title = x.find_element_by_css_selector('.bd p[class=""]')
.text.strip().encode('utf-8')
        pingfen = x.find_element_by_css_selector('.rating_num').text
        pingjia = x.find_element_by_xpath
('.//div[@class="star"]/span[last()]').text
        yingping = x.find_element_by_css_selector('.inq').
text.encode('utf-8')

        print num
        print name
        print title
        print pingfen
        print pingjia
        print yingping



你可能感兴趣的:(selenium爬取豆瓣电影)