CasperJS:当连续两次调用fetchText时,第二个调用不起作用

时间:2014-07-17 00:01:00

标签: phantomjs casperjs

CasperJS版本1.1.0-beta3

casper.start(someLink);

function getUrl(link) {
    casper.thenOpen(basePath + link);
    casper.then(function() {

        var par1 = this.fetchText('body > table > tbody > tr > td > div > table > tbody > tr:nth-child(2) > td > table > tbody > tr > td:nth-child(2) > table > tbody > tr:nth-child(3) > td > table > tbody > tr:nth-child(4) > td:nth-child(2) > table > tbody > tr:nth-child(1) > td:nth-child(2) > strong > span')   
        this.echo(par1);
        var par2 = this.fetchText('body > table > tbody > tr > td > div > table > tbody > tr:nth-child(2) > td > table > tbody > tr > td:nth-child(2) > table > tbody > tr:nth-child(3) > td > table > tbody > tr:nth-child(4) > td:nth-child(2) > table > tbody > tr:nth-child(1) > td:nth-child(3) > strong > span')   
        this.echo(par2);

    });
}

getUrl(someRelativeUrl);

casper.run(function() {
  this.echo('DONE!');
});

问题:par1显示正确的值,par2为空。 我改变了他们的顺序,将par2放在par1之前:在这种情况下,par2显示为right,par1为空。

我做错了什么?显然,fetchText行是正确的,CSS是正确的,但只有第一个取出:下一个都保持为空。

编辑:这里是提供问题的实际html(stackoverflow以某种方式隐藏了代码中的部分和DOCTYPE)。尽可能简单:                         细节                    

<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><div align="center">
      <table width="1000" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td><table width="1000" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="217" valign="top" bgcolor="#E3E5E4"><table width="100%" border="0" cellspacing="0" cellpadding="0">
              </table></td>
              <td width="783" align="left" valign="top" bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td align="right" bgcolor="#D4D6D5"><img src="top.jpg" width="180" height="179" /></td>
                </tr>
                <tr>
                  <td bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td width="3%">&nbsp;</td>
                      <td width="97%">&nbsp;</td>
                    </tr>

                 <tr>
                      <td>&nbsp;</td>
                      <td>&nbsp;</td>
                 </tr>

                 <tr>
                      <td>&nbsp;</td>
                      <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                          <td width="2%">&nbsp;</td>
                          <td width="49%"align="left" class="style10">POLE1: <strong><span class="style7">ADR1 </span></strong></td>
                          <td width="49%"align="left" class="style10">POLE2: <strong><span class="style7">ADR2 </span></strong></td>
                        </tr>
                        <tr>


                      </table></td>
                 </tr>

                              <tr>
                      <td>&nbsp;</td>
                      <td>&nbsp;</td>
                    </tr>
                    <tr>
                      <td>&nbsp;</td>
                      <td>&nbsp;</td>
                    </tr>
                    <tr>
                      <td>&nbsp;</td>
                      <td>&nbsp;</td>
                    </tr>
                  </table></td>
                </tr>
              </table></td>
            </tr>
          </table></td>
        </tr>
        <tr>
          <td bgcolor="#170E13">&nbsp;</td>
        </tr>
      </table>
    </div></td>
  </tr>
</table>

</body>
</html>

谢谢!

0 个答案:

没有答案