我试图制作一个通过python selenium自动编辑文章的脚本,但问题在于:
打开页面后页面本身就很好了,但是我无法获得我想要的元素。证明元素在某些内部,而硒没有打开/读取。
当我使用
时iframe = driver.find_element_by_id('cafe_main').get_attribute('src')
driver.switch_to.frame(iframe)
它没有用。得到了#No; NoSuchFrameException:消息:没有这样的框架"错误。
try:
element = WebDriverWait(driver, 10).until(
expected_conditions.presence_of_element_located((By.XPATH, ".//*[@id='modifyFormBtn']/p/a"))
)
finally:
print(driver.page_source)
但仍然没有....只是得到一个timeoutException和print()在最后部分显示iframe没有加载。
所以...有没有其他方法可以加载这个东西?
编辑: 我尝试在driver.switch_to.frame(iframe)中删除get_attribute(' src'),我收到了此错误。
消息:未知错误:元素不是 点击点(784,864)。其他元素将收到点击: ......(会议信息: chrome = 58.0.3029.110)(驾驶信息:chromedriver = 2.30.477700 (0057494ad8732195794a7b32078424f92a5fce41),platform = Windows NT 10.0.14393 x86_64)
http://cafe.naver.com/twcenter/22498这是我正在使用的链接,应该有div标签中的文章,id =" main-area"区域,但仅在硒中显示
EDIT2:
我的完整代码:
import os
from selenium import webdriver
chromePath = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'chromedriver')
# setting up browser. this is Chrome-based.
driver = webdriver.Chrome(chromePath)
# tha address. for testing it out
driver.get('http://cafe.naver.com/twcenter/22498')
driver.implicitly_wait(15) # tried waiting if dynamic script gets loaded. it didn't.
# opening the frame.
iframe = driver.find_element_by_id('cafe_main')
print(iframe)
driver.switch_to.frame(iframe)
# an xpath going to a button opening forum post lists.
xpath = ".//*[@id='main-area']/div[3]/div/div[2]/p/a"
try:
# not working at the moment as iframe is not being dynamically updated in selenium.
driver.find_element_by_xpath(xpath).click()
except Exception as e:
print(e)