2017-12-27 7 views
0

다른 국가 세관 웹 사이트에서 가져온 세금을 긁는 웹 봇을 개발 중이며 다음 사이트에서 원하는 값을 검색하는 데 문제가 있습니다. http://www.aduanet.gob.pe/itarancel/arancelS01Alias CODIGO 옆의 테스트 값 3303000000. 검색하고자하는 값은 "Ad/Valorem"옆에있는 6 %이지만, ID 속성이나 클래스 또는 이와 직접적으로 관련이 있거나 적어도 그 근처에있는 테이블은 없습니다. 나는 .parent 및 .child 메서드를 사용하려고 시도했지만 성공하지는 못했습니다. 지금까지의 코드는 다음과 같습니다.VBA ID가없는 테이블에서 단일 값 가져 오기

Function Peru(partida As String) As String 

'Open IE 
Set objIE = New InternetExplorer 
objIE.Visible = True 
objIE.navigate "http://www.aduanet.gob.pe/itarancel/arancelS01Alias" 

'Load sub 
Cargar 

'Navigate further into the website (Im using partida = 3303000000) 
For Each box In objIE.document.getElementsByTagName("input") 
    If box.Name = "cod_partida" Then 
     box.Value = partida 
     Exit For 
    End If 
Next 

For Each boton In objIE.document.getElementsByTagName("input") 
    If boton.Value = "Consultar" Then 
     boton.Click 
     Exit For 
    End If 
Next 

'Get the 6% value (This part is the one I cant figure out) 

End Function 
+0

당신이 후에있는 컨텐츠에 도달하려면, 당신은이'iframes'와 장애물에 있습니다. – SIM

답변

0

이 페이지에서 데이터를 가져 오는 방법입니다. 해당 페이지에서 두 개의 iframes을 전환하여 필요한 내용에 도달해야했습니다.

Sub Aduanet_Info() 
    Dim IE As New InternetExplorer, html As HTMLDocument 
    Dim elem As Object, frm As Object, frm1 As Object 

    With IE 
     .Visible = False 
     .navigate "http://www.aduanet.gob.pe/itarancel/arancelS01Alias" 
     Do While .readyState <> READYSTATE_COMPLETE: Loop 
     Set html = .document 
    End With 

    html.getElementsByTagName("input")(0).Value = "3303000000" 
    html.getElementsByTagName("input")(3).Click 
    Application.Wait Now + TimeValue("00:00:05") 

    Set frm = html.getElementsByClassName("autoHeight")(0).contentWindow.document 
    Set frm1 = frm.getElementsByClassName("autoHeight")(1).contentWindow.document 

    For Each elem In frm1.getElementsByTagName("td") 
     If InStr(elem.innerText, "Valorem") > 0 Then MsgBox elem.NextSibling.NextSibling.innerText: Exit For 
    Next elem 

    IE.Quit 
End Sub 

는 출력 :

6% 
+0

대단히 감사합니다! 코드가 완벽하게 작동했습니다. 나는 지금 막 iFrames에 대해서 읽었을 뿐이며, 내가 시도한 모든 것이 효과가 없었던 이유를 이해했다. –

관련 문제