我有一个进入网站的代码,填写表格,然后转到我的网页:http://www.stf.jus.br/portal/jurisprudencia/listarJurisprudencia.asp?s1=%28ICMS+BASE+DE+CALCULO+PIS+COFINS%29&base=baseAcordaos&url
在那个页面中,我需要所有这些“表”的内容。它们具有以下信息:div class =“processosJurisprudenciaAcordaos”
在这些“表格”中有几种类型的信息,我需要它们。
这是迄今为止的代码。 (它只会持续到网页)
Sub tese()
Dim ie As InternetExplorer
Dim pesquisa As String
pesquisa = InputBox("Digite os termos que quer pesquisar: ", "", "")
Set ie = New InternetExplorer
ie.Visible = True
ie.navigate "http://www.stf.jus.br/portal/jurisprudencia/pesquisarJurisprudencia.asp"
ieBusy ie
ie.document.getElementById("txtPesquisaLivre").innerText = pesquisa
ie.document.getElementById("pesquisar").Click
ieBusy ie
Dim elemUnique, elemCollection As Object
Set elemCollection = ie.document.getElementsByTagName("a")
For Each elemUnique In elemCollection
If elemUnique.className Like "linkPagina" Then
elemUnique.Click
Exit For
End If
Next elemUnique
ieBusy ie
End Sub
答案 0 :(得分:0)
您可以将元素设置为IHTMLElementCollection
,然后一次循环收集一个集合,从中获取所需信息。在我的下面的示例中,我使用了一个msgbox来向您显示您抓住了该表。
此代码的上半部分用于测试目的,并向您显示这是正常工作的代码,下面的部分(在行下)是您需要的。
代码:
Sub Test()
Dim ie As New InternetExplorer, Url As String
Url = "http://www.stf.jus.br/portal/jurisprudencia/listarJurisprudencia.asp?s1=%28ICMS+BASE+DE+CALCULO+PIS+COFINS%29&base=baseAcordaos&url"
With ie
.navigate Url
Do While .Busy Or .readyState < READYSTATE_COMPLETE
DoEvents
Loop
.Visible = True
End With
'<------- Above was to Test, you want below this line ------->
Dim tblColl As IHTMLElementCollection, tbl As IHTMLElement
Set tblColl = ie.document.getElementsByClassName("processosJurisprudenciaAcordaos")
For Each tbl In tblColl
'Do what you need to with your table
'Using a MsgBox to show it works
MsgBox tbl.innerText
Next tbl
End Sub