Vídeo recomendado
https://youtu.be/diWPPPhW-9E

quantas tabelas há na página e quantas linhas por tabela?!

A Web está aí, não há como negar. Ela é onipresente em praticamente toda operação eletrônica realizada nos dias de hoje. Como não podia ser diferente, o Excel, ferramenta máxima para analistas e profissionais das mais diversas áreas do mercado precisa estar alinhado com esta necesssidade. E ele está! Neste forum, o debate é focado em expor dúvidas, sugestões, modelos de código e exemplos de uso do Excel na Integração com tecnologias Web.
iancao
Acabou de chegar
Acabou de chegar
Mensagens: 3
Registrado em: Sex Set 20, 2019 2:36 pm

quantas tabelas há na página e quantas linhas por tabela?!

Mensagem por iancao »

Caros,

Após minha última consulta aqui forum procurei aprender um pouco de Selenium e consegui evoluir bastante.

Meu objetivo é extrair alguns dados de tabelas na página da CVM.

O que me parecia mais complicado, que era extrair os valores da página com os detalhes de cada entrada da tabela foi relativamente fácil.

Agora estou apanhando na otimização da rotina:

A ideia é entrar nessa página principal :

http://web.cvm.gov.br/app/esforcosrestr ... o=Mg%3D%3D

E depois clicar em cada linha, o que nos leva á uma página com os detalhes, e extrair esses dados em forma de tabela para o excel.

Eu consegui a segunda parte :
Sub detalhes()
Dim driver As WebDriver
Dim valor As WebElement
Set driver = New ChromeDriver

driver.Get "http://web.cvm.gov.br/app/esforcosrestr ... Zz09In0%3D"

Application.Wait (Now + TimeValue("0:00:03"))
Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[2]/fieldset[2]/div/div/div[1]/div/input")
ofertantecnpj = valor.Value

Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[2]/fieldset[1]/div/div/div[2]/div/input")
ofertantenome = valor.Value

Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[2]/fieldset[1]/div/div/div[3]/div/select")
ofertantetipo = valor.Value
ofertantetipo = ofertantetipo * 1
tipos = Array("Fundo de Investimento", "Cooperativa", "Pessoa Física", "Sociedade Anônima de Capital Aberto", "Sociedade Anônima de Capital Fechado", "Outros")
ofertantetipo = tipos(ofertantetipo - 1)

Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[2]/fieldset[1]/div/div/div[4]/div/input")
endereçoofertanteweb = valor.Value


Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[2]/fieldset[2]/div/div/div[1]/div/input")
emissorcnpj = valor.Value

Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[2]/fieldset[2]/div/div/div[2]/div/input")
emissornome = valor.Value

Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[2]/fieldset[2]/div/div/div[3]/div/select")
emissortipo = valor.Value
emissortipo = emissortipo * 1
tipos = Array("Fundo de Investimento", "Cooperativa", "Pessoa Física", "Sociedade Anônima de Capital Aberto", "Sociedade Anônima de Capital Fechado", "Outros")
emissortipo = tipos(emissortipo - 1)

Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[2]/fieldset[2]/div/div/div[4]/div/input")
endereçoemissorweb = valor.Value


Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[3]/fieldset/div/div/div[1]/div/select")
valormobiliario = valor.Value
valormobiliario = valormobiliario * 1
tipos = Array("AÇÕES ORDINÁRIAS", "AÇÔES PREFERENCIAIS", "BDR PATROCINADO NÍVEL III", "BÔNUS DE SUBSCRIÇÃO", "CÉDULAS DE CRÉDITO BANCÁRIO - CCB", "CÉDULAS DE PRODUTO RURAL - FINANCEIRAS - CPR", "CERTIFICADOS DE DEPÓSITO DE VALORES MOBILIÁRIOS", "CERTIFICADOS DE DIREITOS CREDITÓRIOS DO AGRONEGÓCIO - CDCA", "CERTIFICADOS DE OPERAÇÕES ESTRUTURADAS - COE", "CERTIFICADOS DE RECEBÍVEIS DO AGRONEGÓCIO - CRA", "CERTIFICADOS DE RECEBÍVEIS IMOBILIÁRIOS - CRI", "CONTRATO DE INVESTIMENTO COLETIVO - CIC", "DEBÊNTURES CONVERSÍVEIS", "DEBÊNTURES PERMUTÁVEIS", "DEBÊNTURES SIMPLES", "LETRAS FINANCEIRAS", "NOTAS PROMISSÓRIAS", "COTAS DE FUNDOS DE INVESTIMENTO FECHADOS", "WARRANTS AGROPECUÁRIOS")
valormobiliario = tipos(valormobiliario - 1)
Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[3]/fieldset/div/div/div[2]/div/input")
numemissao = valor.Value


Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[3]/fieldset/div/div/div[3]/div[1]/label/input")
numserie = valor.Value
If numserie = False Then
numserie = "Ùnica"
Else
numserie = "Várias"
End If
Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[3]/fieldset/div/div/div[4]/div/select")
tipooferta = valor.Value
tipooferta = tipooferta * 1
tipos = Array("Primária", "Secundária")
tipooferta = tipos(tipooferta - 1)
Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[3]/fieldset/div/div/div[5]/div/select")
especie = valor.Value
especie = especie * 1
tipos = Array("Garantia Real", "Garantia Flutuante", "Sem Preferência", "Subordinada", "Não Aplicável")
especie = tipos(especie - 1)
Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[3]/fieldset/div/div/div[5]/div/select")
classe = valor.Value
classe = classe * 1
tipos = Array("Sênior", "Subordinada", "Subordinada Mezanino", "Não Aplicável", "Outros")
classe = tipos(classe - 1)
Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[3]/fieldset/div/div/div[5]/div/select")
forma = valor.Value
forma = forma * 1
tipos = Array("Nominativa", "Escritural", "Nominativa e Escritural")
forma = tipos(forma - 1)
Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[3]/fieldset/div/div/div[8]/div/input")
datainicio = valor.Value

Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[3]/fieldset/div/div/div[9]/div[1]/div/div/input")
dataencerramento = valor.Value

Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[3]/fieldset/div/div/div[9]/div[2]/div/select")
garantiastotais = valor.Value
garantiastotais = garantiastotais * 1
tipos = Array("Penhor", "Fidejussória", "Hipoteca", "Não Aplicável", "Outra")
garantiastotais = tipos(garantiastotais - 1)
Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[3]/fieldset/div/div/div[9]/div[3]/div/input")
quantidade = valor.Value

Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[3]/fieldset/div/div/div[9]/div[4]/div/input")
preco = valor.Value

Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[3]/fieldset/div/div/div[9]/div[5]/div/input")
valorsubscrito = valor.Value

Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[3]/fieldset/div/div/div[9]/div[6]/div/div/label[1]/input")
lei12431 = valor.Value
If lei12431 = False Then
lei12431 = "Sim"
Else
numserie = "Não"
End If
Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[5]/fieldset/div[1]/div/table/tbody/tr[1]/td[2]/input")
pfnum = valor.Value

Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[5]/fieldset/div[1]/div/table/tbody/tr[1]/td[3]/input")
pfquantidade = valor.Value

Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[5]/fieldset/div[1]/div/table/tbody/tr[2]/td[2]/input")
clubesnum = valor.Value

Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[5]/fieldset/div[1]/div/table/tbody/tr[2]/td[3]/input")
clubesquantidade = valor.Value

Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[5]/fieldset/div[1]/div/table/tbody/tr[3]/td[2]/input")
fundosnum = valor.Value

Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[5]/fieldset/div[1]/div/table/tbody/tr[3]/td[3]/input")
fundosquantidade = valor.Value

Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[5]/fieldset/div[1]/div/table/tbody/tr[4]/td[2]/input")
prevprivadanum = valor.Value

Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[5]/fieldset/div[1]/div/table/tbody/tr[4]/td[3]/input")
prevprivadaquantidade = valor.Value

Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[5]/fieldset/div[1]/div/table/tbody/tr[5]/td[2]/input")
seguradorasnum = valor.Value

Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[5]/fieldset/div[1]/div/table/tbody/tr[5]/td[3]/input")
seguradorasquantidade = valor.Value

Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[5]/fieldset/div[1]/div/table/tbody/tr[6]/td[2]/input")
estrangeirosnum = valor.Value

Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[5]/fieldset/div[1]/div/table/tbody/tr[6]/td[3]/input")
estrangeirosquantidade = valor.Value

Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[5]/fieldset/div[1]/div/table/tbody/tr[7]/td[2]/input")
intermediariosnum = valor.Value

Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[5]/fieldset/div[1]/div/table/tbody/tr[7]/td[3]/input")
intermediarioquantidade = valor.Value

Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[5]/fieldset/div[1]/div/table/tbody/tr[8]/td[2]/input")
bancosparticipantesnum = valor.Value

Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[5]/fieldset/div[1]/div/table/tbody/tr[8]/td[3]/input")
bancosparticipantequantidade = valor.Value

Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[5]/fieldset/div[1]/div/table/tbody/tr[9]/td[2]/input")
demaisbancossnum = valor.Value

Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[5]/fieldset/div[1]/div/table/tbody/tr[9]/td[3]/input")
demaisbancosquantidade = valor.Value

Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[5]/fieldset/div[1]/div/table/tbody/tr[10]/td[2]/input")
pjligadassnum = valor.Value

Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[5]/fieldset/div[1]/div/table/tbody/tr[10]/td[3]/input")
pjligadasquantidade = valor.Value

Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[5]/fieldset/div[1]/div/table/tbody/tr[11]/td[2]/input")
demaispjsnum = valor.Value

Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[5]/fieldset/div[1]/div/table/tbody/tr[11]/td[3]/input")
demaispjquantidade = valor.Value

Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[5]/fieldset/div[1]/div/table/tbody/tr[12]/td[2]/input")
colaboradoresligadossnum = valor.Value

Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[5]/fieldset/div[1]/div/table/tbody/tr[12]/td[3]/input")
colaboradoresligadosquantidade = valor.Value

Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[5]/fieldset/div[1]/div/table/tbody/tr[13]/td[2]/input")
outrossnum = valor.Value

Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[5]/fieldset/div[1]/div/table/tbody/tr[13]/td[3]/input")
outrosquantidade = valor.Value

Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[5]/fieldset/div[2]/div[1]/div/div[1]/label[1]/input")
gestoresmaisdeumfundo = valor.Value
If gestoresmaisdeumfundo = False Then
gestoresmaisdeumfundo = "Sim"
Else
gestoresmaisdeumfundo = "Não"
End If
Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[5]/fieldset/div[2]/div[1]/div/div[2]/div/input")
numerofundosmesmogestor = valor.Value

Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[5]/fieldset/div[2]/div[2]/div/div/label[1]/input")
administradormaisdeumcliente = valor.Value
If administradormaisdeumcliente = False Then
administradormaisdeumcliente = "Não"
Else
administradormaisdeumcliente = "Sim"
End If
Set valor = driver.FindElementByXPath("/html/body/div[1]/div[1]/div[4]/div/div[2]/div[5]/fieldset/div[2]/div[3]/div/div/label[1]/input")
ofertaexterior = valor.Value
If ofertaexterior = False Then
ofertaexterior = "Não"
Else
ofertaexterior = "Sim"
End If

driver.Quit
End Sub

Mas não estou conseguindo criar um processo de navegação eficiente para a primeira parte.

Preciso saber quantas tabelas(ou meses) há na página inicial e quantas linhas(ou ativos) há em cada mês, para poder fazer um loop para as páginas de detalhes.

Não consigo de forma alguma achar esse parâmetros. O melhor que consegui foi um string de texto, com todos os dados da página. Daria para fazer uma gambiarra com esse string e chegar ao numero de meses e de ativos mas certamente há uma forma mais inteligente.

Alguma ideia ?

Agradeço muito.

Um abraço,

Ian


Disable adblock

This site is supported by ads and donations.
If you see this text you are blocking our ads.
Please consider a Donation to support the site.


Responder