Phantomjs脚本无法打印到控制台或等待页面加载

时间:2019-01-16 18:19:36

标签: phantomjs

我需要帮助来理解示例代码中的两点错误:

var url = 'https://www.zacks.com/earnings/earnings-calendar'; var fs = require('fs'); var page = require('webpage').create(); page.open(url, function(status) {
    if (status === 'success') {
        var html = page.evaluate(function() {           document.getElementById("tab9").click();            setTimeout(function(){
                console.log("2");           }, 5000);           return document.getElementById("earnings_rel_data_all_table_wrapper").outerHTML;
        });
        try {
            fs.write("C:\\Users\\Douglas\\Downloads\\phantomjs\\bin\\sales.txt", html, 'w');
        } catch(e) {
            console.log(e);
        }
    }
    phantom.exit(); });

脚本运行无错误。 该脚本确实将文本文件保存到目录中。

问题1:查看以下输出,它将保存短语“ Loading”,因此setTimeout函数不能正常工作。但为什么?我有什么语法错误?

<td valign="top" colspan="10" class="dataTables_empty">
Loading...</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="bottom_value_wrapper">
<div class="dataTables_info" id="earnings_rel_data_all_table_info" role="status" aria-live="polite">
Showing 0 to 0 of 0 entries</div>

问题2:console.log消息均未运行。为什么?

感谢您的输入!

0 个答案:

没有答案