【发布时间】:2021-01-25 02:24:47
【问题描述】:
我正在尝试使用 selenium 和 beautifulsoup 4 抓取一个加载了 javascript 的网站 https://e-consulta.sunat.gob.pe/cl-at-ittipcam/tcS01Alias。
但是,当尝试从树中检索元素或子项(子分支)时,我收到此错误
bloquefecha=bloque.find('div[@class="date"]').text
AttributeError: 'NoneType' 对象没有属性 'text'
i'm attaching HERE a snapshot of my code and the developers console for illustrative purposes
这是我的代码:
def beautifulseleniumsunat2():
navegador = webdriver.Chrome()
navegador.get("https://e-consulta.sunat.gob.pe/cl-at-ittipcam/tcS01Alias")
time.sleep(7) # esperamos 7 segundos a que cargue la pagina
pagsunat = navegador.page_source
soup = BeautifulSoup(pagsunat, "html.parser")
print (soup.prettify())
bloquesdias2 = soup.select('td[class*="table-bordered calendar-day current"]')
listafecha = []
listacompra=[]
listaventa=[]
for bloque in bloquesdias2:
bloquefecha=bloque.find('div[@class="date"]') #ALSO tried with findall and iterating with FOR loop on each element but ERROR says it's not iterable
listafecha.append(bloquefecha.text)
bloquecompra=bloque.find('div[@class="event normal-all-day begin end"]') #ALSO tried with findall and iterating with FOR loop on each element but ERROR says it's not iterable
listacompra.append(bloquecompra.text)
bloqueventa = bloque.find('div[@class="event pap-all-day begin end"]') #ALSO tried with findall and iterating with FOR loop on each element but ERROR says it's not iterable
listaventa.append(bloquecompra.text)
listafinal=[listacompra,listaventa,listafecha]
print (listafinal)
【问题讨论】:
标签: python selenium beautifulsoup