如何在噩梦中通过document.queryselector()访问标签

时间:2018-07-26 13:08:37

标签: javascript node.js nightmare

我想访问噩梦中的<td>0.0039</td>,当我访问标签的属性时代码可以正常工作,但是在这里我要访问类的数据

<table class="order-book left">
  <thead>
    <tr>
      <th></th>
      <th class="right">VOLUME</th>
      <th class="right">BUY PRICE</th>
    </tr>
  </thead>
  <tbody class="buy">
    <tr>
      <td>
        <div></div>
      </td>
      <td>0.0039</td>
      <td>8242.000</td>
      <div class="filler" style="width: 0.148212%;"></div>
    </tr>
    <tr>
      <td>
        <div></div>
      </td>
      <td>0.0196</td>
      <td>8240.000</td>
      <div class="filler" style="width: 0.74486%;"></div>
    </tr>
    <tr>
      <td>
        <div></div>
      </td>
      <td>0.0605</td>
      <td>8230.000</td>
      <div class="filler" style="width: 2.29918%;"></div>
    </tr>
    <tr>
      <td>
        <div></div>
      </td>
      <td>0.0705</td>
      <td>8205.022</td>
      <div class="filler" style="width: 2.67921%;"></div>
    </tr>
    <tr>
      <td>
        <div></div>
      </td>
      <td>0.1431</td>
      <td>8205.002</td>
      <div class="filler" style="width: 5.43824%;"></div>
    </tr>
    <tr>
      <td>
        <div></div>
      </td>
      <td>0.1450</td>
      <td>8204.000</td>
      <div class="filler" style="width: 5.51044%;"></div>
    </tr>
    <tr>
      <td>
        <div></div>
      </td>
      <td>0.1485</td>
      <td>8200.000</td>
      <div class="filler" style="width: 5.64345%;"></div>
    </tr>
    <tr>
      <td>
        <div></div>
      </td>
      <td>0.1502</td>
      <td>8180.000</td>
      <div class="filler" style="width: 5.70806%;"></div>
    </tr>
    <tr>
      <td>
        <div></div>
      </td>
      <td>0.1512</td>
      <td>8175.000</td>
      <div class="filler" style="width: 5.74606%;"></div>
    </tr>
    <tr>
      <td>
        <div></div>
      </td>
      <td>0.1810</td>
      <td>8158.000</td>
      <div class="filler" style="width: 6.87855%;"></div>
    </tr>
  </tbody>
</table>

我的代码:-

const Nightmare = require('nightmare')
const nightmare = Nightmare({ show: true })

nightmare
  .goto('https://wazirx.com/exchange/BTC-USDT')
  .wait(5000)
  .evaluate(() => document.querySelector('.buy td'))
  .end()
  .then(function (href){console.log(href);})
  .catch(error => {
    console.error('Search failed:', error)
  })

0 个答案:

没有答案