2017-12-06 1 views
0

I 예 .FOR, 다음과 같은 HTML을 파싱 한 후 리턴 <th>Number of samples</th>하에 <td colspan="2">...</td> 간의 정보를 파싱 할 64간에 데이터를 파싱하기 <TD 열 병합 = "2"> 및</td>

... 
<tr class="border"> 
    <th>Average FPKM</th> 
    <td colspan="2">0.8</td> 
</tr> 
<tr class="border"> 
    <th>Number of samples</th> 
    <td colspan="2">64</td> 
</tr> 
... 

방법 여기서 값 64 만 돌려 받으시겠습니까?

감사

+0

안녕하세요 도움이되기를 바랍니다, 나는 그가 BeautifulSoup로, 파이썬 라이브러리이 값을하고 싶어 가정 해 봅시다. 아름다운 스프에 대한 문서는 다음과 같습니다. https://www.crummy.com/software/BeautifulSoup/bs4/doc/ – MEE

+0

javascript를 사용할 수 있도록 div와 table을 사용하여 코드를 자세하게 게시하십시오. –

+0

다른 사람들에게 유용 할 수 있도록 자신의 솔루션을 게시하고 대답으로 표시하십시오. – MEE

답변

1

첫 번째 테이블은 내가 순수 자바 스크립트없이 JQuery와,이 코드는 당신이 jQuery를 사용

var value = document.getElementById("tableCell").innerHTML 

를 원하는 것을 정확하게 수행하여

tableCell을 선택이 예를 들어, ID를 셀 줄 이렇게 할 수 있습니다 :

var value = $("#tableCell").html() 
+0

고마워요. 이미 해결되었습니다. –

+0

좋습니다! 내 게시물을 대답으로 표시 할 수 있다면 좋을 것입니다 – DerJP

0

마지막 ce ll은 테이블의 마지막 행과 jQuery를 사용하고있다.

let result = $('table tr:last-child td:last-child').text(); 

Here is example

+0

고마워요. 나는 이미 혼자서 해결했다. –

1

하는 일, 다음의 부모를 가져 오기, 다음 TD를 찾을 수 있습니다.

$(document).ready(function() { 
    var thGet=$('table').find('th'); 
    $.each(thGet, function (i, obj) { 
    var text = $(obj).text(); 
    if(text == 'Number of samples' && $(obj).parent().find('td').attr('colspan') == '2') 
    { 
     alert($(obj).parent().find('td').html()); 
    } 
    }); 
}); 

비 jQuery를 순수 Javascript.I가 변경되지 않는 테이블 tr의 구조를 가정하면이 방법을 따를 수 자바 스크립트를 지원을

var x = document.querySelectorAll('th'); 
for (var i = 0; i < x.length; i++) { 
    if(x[i].innerHTML == 'Number of samples') 
    { 
     var c = x[i].parentNode.childNodes; 
     var j; 
     for (j = 0; j < c.length; j++) { 
      if(c[j].tagName == 'TD' && c[j].colSpan == '2') 
      { 
      console.log(c[j].innerHTML); 
      } 
     } 
    } 
}; 
+0

참고 :이 솔루션에는 jQuery가 필요합니다. – MEE

+0

나 혼자만의 덕택으로 고마워. –

1

이 필요합니다.

  1. 모든 tr.border

  2. 그들을 반복 매우 간단 Number of samples이있는 일 찾기를 선택합니다. 그런 다음 원하는 것을 얻으십시오.

    window.onload =() => { 
     
        let tr = document.querySelectorAll('tr.border') 
     
        tr.forEach((elm) => { 
     
         if(elm.innerText.indexOf('Number of samples') == 0) 
     
          console.log(elm.querySelector('td').innerText) 
     
        }) 
     
    };
    <table> 
     
    <tr class="border"> 
     
        <th>Average FPKM</th> 
     
        <td colspan="2">0.8</td> 
     
    </tr> 
     
    <tr class="border"> 
     
        <th>Number of samples</th> 
     
        <td colspan="2">64</td> 
     
    </tr> 
     
    </table>

그것이