2017-12-24 1 views
-2

개인 프로젝트에서 웹 사이트에서 정보를 얻고 있습니다. 웹 사이트에 테이블이 있습니다. 각 행을 반복하는 방법을 알고 있습니다. 각 행에 대해 첫 번째와 네 번째 열의 내용과 정보를 비교하고 싶습니다. 둘 다 내 테이블의 정보와 일치하면 해당 행의 다섯 번째 열의 내용을 내 테이블을 만들지 만이 일을하는 법을 모르겠다. 테이블 html의 각 행은 다음과 같습니다. 여기 HTML 테이블 행의 세 번째 요소 가져 오기 VBA

<tr class="player_tr_1" data-url="/18/player/1/Pelé"> 
    <td class="table-row-text" style="text-align: left;"> 
     <img style="padding: 0;" class="player_img player_right_curve 
     form rating icon gold rare" src="./FIFA 18 Players _ 
     FUTBIN_files/237067.png">          
//Check info here 
     <a href="https://www.futbin.com/18/player/1/Edson%20Arantes" 
     class="player_name_players_table"> CHECK THIS TEXT </a> 
    </td> <td><span class="form rating icon gold rare">98</span> </td> 
    <td class="">CAM</td> 
    //Check info here 
    <td class="">CHECK THIS INFO</td> 
    //Grab info here 
    <td><span class="ps4_color"> GRAB THIS INFO </span></td> 
    <td><span class="xb1_color">0</span></td> 
    <td><span class="pc_color">0</span></td> 
    <td><span class="yellow_players_stat">76</span></td> 
    <td>173cm | 5'8"</td> 
    <td>77</td> 
    <td>516</td> 
    <td>2513</td> 
</tr> 

내가 지금까지 가지고있는 코드 : 그것은 테이블에 내가 그 행의 정보를 잡아 필요가있는 루프의 각 행을 반복. 당신의 HTML에서 내가 클래스 이름이없는 잡기 위해 노력하고있어 요소를 볼 수 있듯이 : 나는 특히

Private Sub CommandButton1_Click() 
     SearchBot 
End Sub 

'start a new subroutine called SearchBot ' 
Sub SearchBot() 

'dimension (declare or set aside memory for) our variables 
Dim objIE As InternetExplorer 'special object variable representing the IE browser 
Dim aEle As HTMLHtmlElement 
Dim X As Integer 'integer variable we'll use as a counter 
Dim version As String 'string variable that will hold our version ' 
Dim NumRows As Integer 


'initiating a new instance of Internet Explorer and asigning it to objIE 
Set objIE = New InternetExplorer 

'make IE browser visible (False would allow IE to run in the background) 
objIE.Visible = True 



' Set numrows = number of rows of data. 
NumRows = Range("A2", Range("A2").End(xlDown)).Rows.Count + 1 
' Select cell a1. 
Range("A2").Select 
' Establish "For" loop to loop "numrows" number of times. 

' screen is updated every time a new price is inserted ' 
Application.ScreenUpdating = True 

For X = 2 To NumRows 
    ' go to player page with correct name ' 
    objIE.navigate "https://www.futbin.com/18/players?page=1&search=" & Sheets("Sheet1").Range("A" & X).Value 


    ' wait ' 
    Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop 


    ' loop through each row ' 
    For Each aEle In objIE.document.getElementsByTagName("tr") 
     ' check player name, if correct loop through table to grab price if it is also the right version maybe or' 
     ' or grab first elements text content, check if correct name, check 4th element for correct version, grab 5th element, and insert in table ' 

     'if 1st element = Sheets("Sheet1").Range("A" & X).Value & "" ' 
     ' And 4th element = Sheets("Sheet1").Range("B" & X).Value Then ' 
     'Sheets("Sheet1").Range("F" & X).Value = 5th element ' 
    Next 
Next 
' click the correct version of the player ' 


'close the browser 
objIE.Quit 
MsgBox ("Done") 

'exit our SearchBot subroutine ' 
End Sub 

편집을해야 할 일을 내가 위해 루프에 댓글을 달았습니다.

미리 감사드립니다.

+2

어디에서 * 각 행을 반복하는 방법을 알고 있습니까 *? 왜'vb.net','vba' 및'excel' 태그를 설정 했습니까? – JohnyL

+0

스택 오버플로에 오신 것을 환영합니다! 당신이 시도한 것을 보여 주시고 어떤 기술을 사용하고 계신지 명확히하십시오. VBA와 VB.NET은 동일하지 않으며 .NET은 VB.NET 및 Excel과 VBA 만 관련됩니다. –

+0

안녕하세요 @ JohnyL 나는 vba를 사용하고 Excel을 사용하기 때문에 태그를 설정했습니다. 그리고 .net 때 스택 오버플로 시각적 기본을 찾습니다. 닷넷 문제가 올라와. 곧 수정 코드에 추가하겠습니다. 끝 부분에 포함하는 것을 잊어 버렸습니다. – TheHeuman

답변

0

식별 할 수있는 ID/클래스가없는 요소가 하나 뿐인 것처럼 보이므로 클래스 이름으로 나머지를 가져 오는 동안 색인으로 가져와야합니다. 나는 매우 VBA에 익숙하지 않아요

Dim FirstColumn As String 
Set FirstColumn = aEle.getElementsByClassName("player_name_players_table")(1).innerText 

Dim FourthColumn As String 
Set FourthColumn = aEle.getElementsByTagName("td")(4).innerText 

Dim FifthColumn As String 
Set FifthColumn = aEle.getElementsByClassName("ps4_color")(1).innerText 

주 (내가 VB.NET 사람이야) 그래서 나는 모든 구문이 올바른지 여부를 확신하지 않으며, 반환 된 배열은 시작은 제로 경우 또는 하나. :)

+0

의견은 확장 토론이 아닙니다. 이 대화는 [채팅으로 이동되었습니다] (http://chat.stackoverflow.com/rooms/161946/discussion-on-answer-by-visual-vincent-grab-third-element-in-html-table-row- vba). –

관련 문제