【问题标题】:Why isn't Ghost.py loading/running my Javascript?为什么 Ghost.py 不加载/运行我的 Javascript?
【发布时间】:2013-11-08 05:24:54
【问题描述】:

Ghost.py 应该运行 JS:http://jeanphix.me/Ghost.py/

require.js 通过 http 获取,但据我所知,它没有运行,因为“js/main.built”永远不会被获取,并且它指定的 JS 文件都没有被加载。这一切都可以在真正的浏览器中完美运行。

In [51]: ghost = Ghost(wait_timeout=60)

In [52]: page, resources = ghost.open(url)

In [53]: [r.url for r in resources]
Out[53]: 
[PyQt4.QtCore.QUrl(u'https://example.com/#consume/283e6571bcecf34143cbd60f35e0464b'),
 PyQt4.QtCore.QUrl(u'https://example.com/css/ui.css'),
 PyQt4.QtCore.QUrl(u'https://example.com/css/colorpicker.css'),
 PyQt4.QtCore.QUrl(u'https://example.com/css/selectize.default.css'),
 PyQt4.QtCore.QUrl(u'https://example.com/css/datepicker.css'),
 PyQt4.QtCore.QUrl(u'https://example.com/css/site.css'),
 PyQt4.QtCore.QUrl(u'https://example.com/css/jquery.fileupload-ui.css'),
 PyQt4.QtCore.QUrl(u'https://example.com/css/style.css'),
 PyQt4.QtCore.QUrl(u'https://example.com/css/bootstrap.css'),
 PyQt4.QtCore.QUrl(u'https://example.com/css/redactor.css'),
 PyQt4.QtCore.QUrl(u'https://example.com/js/lib/require.js')]

In [54]: ghost.con
ghost.confirm  ghost.content  

In [54]: ghost.content
Out[54]: u'<!DOCTYPE html><html lang="en"><head>\n    <meta charset="utf-8">\n    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">\n    <title>Ving</title>\n\n    <link rel="stylesheet" href="css/ui.css">\n    <link rel="stylesheet" href="css/bootstrap.css">\n    <link rel="stylesheet" href="css/colorpicker.css">\n    <link rel="stylesheet" href="css/redactor.css">\n    <link rel="stylesheet" href="css/site.css">\n    <link rel="stylesheet" href="css/selectize.default.css">\n    <!-- My Bug fixes / overrides to work with real app -->\n    <link rel="stylesheet" href="css/style.css">\n    <link rel="stylesheet" href="css/datepicker.css">\n    <!-- Theme for uploader -->\n    <link rel="stylesheet" href="css/jquery.fileupload-ui.css">\n    <!-- Shims for IE support  -->\n    <!--[if lte IE 8]>\n      <script src="js/lib/html5shiv.js"></script>\n      <script src="js/lib/r2d3.min.js" charset="utf-8"></script>\n    <![endif]-->\n  </head>\n\n  <body>\n    <div id="wrapper">\n      <header id="header" class="container"></header>\n      <div id="content" class="container"></div>\n    </div>\n    <footer id="footer" class="container"></footer>\n    <div id="modal" class="modal modal-box hide fade"></div>\n    <script data-main="js/main.built" src="js/lib/require.js"></script>\n\n  \n\n</body></html>'

In [55]:

我也尝试加载“https://mail.google.com/”:

In [7]: url='https://mail.google.com/'

In [8]: ghost = Ghost(wait_timeout=60)

In [9]: page, resources = ghost.open(url)

In [10]: ghost.content
Out[10]: u'<html><head><meta http-equiv="Refresh" content="0;URL=https://mail.google.com/mail/"></head><body><script type="text/javascript" language="javascript"><!--\nlocation.replace("https://mail.google.com/mail/")\n--></script></body></html>'

In [11]: 

【问题讨论】:

  • 您找到解决方案了吗?
  • 不,所以我只是切换到 PhantomJS。在 Python 中工作会很好,但是哦。
  • JS 可以在哪些浏览器上正常运行?
  • 火狐、Chrome、IE。我尝试了其他带有 JS 的页面,但这些页面也不起作用。

标签: javascript python requirejs ghost.py


【解决方案1】:

由于 require.js 异步加载内容,您必须等待自定义条件,例如:

g = Ghost()
g.open(url, wait=False)
page, resources = g.wait_for_text('something made by require.js')

【讨论】:

  • 问题是 JS 永远不会被执行。 wait_for_text() 对我不起作用。
【解决方案2】:

尝试从 python 程序而不是从 ipython 或其他交互式提示符运行 ghost。这似乎是 ghost 或 qt 的问题。

【讨论】:

    猜你喜欢
    • 2018-03-15
    • 2016-06-29
    • 1970-01-01
    • 1970-01-01
    • 2011-07-22
    • 2011-05-12
    • 2021-12-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多