我希望能够从this website抓取票证信息。在切换到iframe后尝试访问元素时,我目前收到过时的错误问题。我希望能够遍历日历日,并能够查看不同日期的可用票证。
我尝试使用不同的方法来访问iframe,例如使用WebDriverWait().until(EC.frame_to_avaiable_and_switch_to_it()
,还尝试使用XPATH
,CLASS_NAME
和CSS_SELECTOR
查找iframe元素。
def get_available_dates(driver, delay=30):
elm = (By.XPATH, '//iframe')
iframe = WebDriverWait(driver, delay).until(EC.frame_to_be_available_and_switch_to_it(elm))
iframes = driver.find_elements_by_xpath("//iframe")
print len(iframes) #Sometimes this shows 0, 1, or 5
driver.switch_to.frame(iframe) #sometimes throw error
elm = (By.CLASS_NAME, 'CalendarMonth_table.CalendarMonth_table_1')
calendar_table = WebDriverWait(driver, delay).until(EC.presence_of_element_located(elm)) #Throws Timeout Exception or iframe stale error
rows = calendar_table.find_elements_by_tag_name('tr')
print "row cnt: {}".format(len(rows))
print rows
我将预期结果和错误添加为评论