我有以下代码:
from selenium import webdriver
import time
browser = webdriver.Firefox()
def navigate (URL):
startTime = time.time()
browser.get(URL)
endTime = time.time()
loadTime = round(endTime - startTime,2)
return loadTime
def checkHomepage():
campaigns = []
rows = len(browser.find_elements_by_xpath('//*[@id="page-top"]/div[4]/div/div/div[6]/div')) #first element is the title bar
for i in range(2,rows+1):
for j in range(1,4):
campaign = browser.find_element_by_xpath('//*[@id="page-top"]/div[4]/div/div/div[6]/div['+str(i)+']/div['+str(j)+']/div/div/p/a')
name = campaign.text
link = campaign.get_attribute('href')
campaigns.append([name, link])
for i in campaigns:
navigate(i[1])
以及其他一些功能
我做:
navigate(link)
login(user,pass)
checkHomepage()
但是,我得到了AttributeError:'float'对象在checkHomepage中没有属性'time' 如果我打印(时间)它会返回一个浮点数。
为什么时间(仅在导航中本地使用)存储为全局?