from selenium import webdriver
from datetime import *
import time starttime = datetime.now()
print ("start time:%s" %starttime)
dr = webdriver.Firefox() url = "http://www.sohu.com"
print('now access %s' %url) dr.get(url)
#time.sleep(3) endtime = datetime.now()
print ("end time:%s"%endtime) print("u共花费毫秒:",endtime-starttime).microseconds dr.quit()
报错:SyntaxError: Non-ASCII character '\xe5' in file D:/pcode/xx.py on line 21, but no encoding declared
修改后成功代码:
#coding=utf-8
from selenium import webdriver
from datetime import *
import time starttime = datetime.now()
print ("start time:%s" %starttime)
dr = webdriver.Firefox() url = "http://www.sohu.com"
print('now access %s' %url) dr.get(url)
#time.sleep(3) endtime = datetime.now()
print ("end time:%s"%endtime) info = u'共花费时间:(秒)'
print(info.encode('utf-8')+str((endtime-starttime).seconds)) dr.quit()