phantomjs - JavaScript, get value of table without ID -


this table , want value of "spielzeit" , "coins".

i've tried lot like

document.queryselector("div.page spielzeit");  document.getelementbyid('page').getelementsbytagname('th');  document.queryselectorall("#page th");   

but nothing worked.

i cant find table, because there no table id.

maybe know how "find" values.

thanks

<div id="page">     <table style="margin-left: 125px; margin-top:50px; width: 300px;">         <tbody>             <tr>                 <th style="text-align: left;">benutzername:</th>                 <th style="color: #9e7538; text-align: right;">dantes999</th>             </tr>             <tr>                 <th style="text-align: left;">reich:</th>                 <th style="color: #9e7538; text-align: right;">not empire</th>             </tr>             <tr>             </tr>             <tr>                 <th style="text-align: left;">charaktere:</th>                 <th style="color: #9e7538; text-align: right;">0</th>             </tr>             <tr>                 <th style="text-align: left;">spielzeit:</th>                 <th style="color: #9e7538; text-align: right;"> minuten</th>             </tr>             <tr>                 <th style="text-align: left;">coins:</th>                 <th style="color: #9e7538; text-align: right;">0 i-coins</th>             </tr>             <tr>                 <th style="text-align: left;">coins:</th>                 <th style="color: #9e7538; text-align: right;">0 v-coins</th>             </tr>             <tr>                 <th style="text-align: left;">lagerpasswort:</th>                 <th style="color: #9e7538; text-align: right;">000000</th>             </tr>             <tr>                 <th style="text-align: left;">loeschcode:</th>                 <th style="color: #9e7538; text-align: right;">1234567</th>             </tr>         </tbody>     </table> </div> 

if there's 1 table on page, document.queryselector("table").get(0) should give table.

second, page id in html, not class. should selected # not .

you can change html this:

<div id="page">  <table style="margin-left: 125px; margin-top:50px; width: 300px;">     <tbody><tr>         <th class="item" style="text-align: left;">benutzername:</th> <th class="value" style="color: #9e7538; text-align: right;">dantes999</th>     </tr>     <tr>         <th class="item" style="text-align: left;">reich:</th> <th  class="value" style="color: #9e7538; text-align: right;">not empire</th>     </tr><tr>     </tr><tr>         <th class="item" style="text-align: left;">charaktere:</th>  <th class="value" style="color: #9e7538; text-align: right;">0</th>     </tr>     <tr>         <th class="item" style="text-align: left;">spielzeit:</th> <th    class="value" style="color: #9e7538; text-align: right;"> minuten</th>     </tr>     <tr>         <th class="item" style="text-align: left;">coins:</th> <th   class="value" style="color: #9e7538; text-align: right;">0 i-coins</th>     </tr>     <tr>         <th class="item" style="text-align: left;">coins:</th> <th   class="value" style="color: #9e7538; text-align: right;">0 v-coins</th>     </tr>      <tr>         <th class="item" style="text-align: left;">lagerpasswort:</th> <th class="value" style="color: #9e7538; text-align: right;">000000</th>     </tr>     <tr>         <th class="item" style="text-align: left;">loeschcode:</th> <th class="value" style="color: #9e7538; text-align: right;">1234567</th>     </tr>      </tbody></table> 

now can use document.queryselector(".item[text='spielzeit']); select corresponding item , text of it's next element value

so code should be:

var elem = document.queryselector(".item[text='spielzeit']"); var value = elem.parentnode.queryselectorall('.value').html; 

Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -