我正在尝试在网站上进行一些数据挖掘。我在for
循环中将selenium与webdriver一起使用。问题是当我将其设置为等待一段时间时,我的代码会崩溃。
在网站上,您需要单击图像,该图像将发送命令给您文件。对于Firefox,您需要指定是要下载还是保存它。这已经解决了,但是当涉及到下一个网站时就是崩溃。
问题在于最后一行导致TypeError: 'str' object is not callable
。
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
profile = webdriver.FirefoxProfile()
profile.set_preference("browser.download.folderList", 2)
profile.set_preference("browser.download.manager.showWhenStarting", False)
profile.set_preference("browser.download.dir", "D:path")
profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/vnd.google-earth.kml+xml")
for i in urls['tubicacion']:
driver = webdriver.Firefox(firefox_profile=profile,
executable_path=r'path\geckodriver-v0.24.0-win64\geckodriver.exe')
driver.maximize_window()
driver.get(i)
elemen = driver.find_element_by_xpath('//*[@id="GOOGLE"]').click()
driver.implicitly_wait(0)
follow = WebDriverWait(driver,5).until(EC.invisibility_of_element_located(By.XPATH('//*[@id="GOOGLE"]'))).click().close()
我也尝试了最后一行,例如:
WebDriverWait(driver,5).until(EC.invisibility_of_element_located(By.XPATH('//*[@id="GOOGLE"]').text)).click().close()
答案 0 :(得分:0)
这应该可以解决您的问题,删除.text。我也删除了.close
WARNING There is no info, I am returning -1
R value is: None
Type of R is <class 'NoneType'>
答案 1 :(得分:0)
元组使用By.XPATH
WebDriverWait(driver,5).until(EC.visibility_of_element_located((By.XPATH, '//*[@id="GOOGLE"]')))