#encoding=utf-8 from selenium import webdriver from selenium.webdriver.common.keys import Keys import time driver = webdriver.PhantomJS() #获取浏览器 driver.get('http://top.zhan.com/') #打开要爬取的页面 time.sleep(3) #等待3s,让页面加载完全 with open('liulong.html','w') as file: #将爬取的代码储存到本地 file.write(driver.page_source.encode('utf-8')) # print type(driver.page_source.encode('utf-8')) driver.quit() #关闭浏览器