硒遍历页面时找不到元素

时间:2018-12-18 14:45:05

标签: python selenium web-scraping

我是新手,我一直在尝试使用selenium自动搜索特定主题,当第二步加载页面时,我无法使它正常工作,非常感谢您的帮助!这是我的代码:

from selenium import webdriver
import sqlite3

def get_web(busqueda):
    #obtencion de datos de pagina web
    print("Runnig: Obtencion de datos de pagina web")
    url_data = 'http://jurisprudencia.poder-judicial.go.cr/SCIJ_PJ/busqueda/jurisprudencia/jur_libre.aspx'
    driver = webdriver.Chrome()
    driver.get(url_data)
    try:
        driver.find_element_by_name('txtConsulta').send_keys(busqueda)
        driver.find_element_by_name('cmdBuscar').click()
    except Exception as e:
        print(e)


    try:
        driver.find_element_by_link_text('Texto de la sentencia').click()
        print(driver.page_source)
        driver.implicitly_wait(10)  # seconds
        texto = driver.find_element_by_css_selector('div.Section1').text
        print('text: ', texto)
    except Exception as e:
        print(e)
    driver.close()


get_web('uber')

1 个答案:

答案 0 :(得分:0)

它在框架中,您需要先切换到

driver.switch_to.frame(driver.find_element_by_css_selector('[name="MainFrame"]')) 
texto = driver.find_element_by_css_selector('div.Section1').text