Question

I'm building a script to monitor a reporting service. Depending on how it takes to process the report the report appears in HTML or comes via XmlHttpRequest.

As a tool to check the page I want to use spynner, which works perfect for HTML, but it seems that I can't get it to work when the data comes via XHR.

The code for the test is the following:

    #!/usr/bin/env python

# -*- coding: utf-8 -*-
__docformat__ = 'restructuredtext en'

from time import sleep
from spynner import browser
import pyquery
from PyQt4.QtCore import QUrl
from PyQt4.QtNetwork import QNetworkRequest, QNetworkAccessManager
from PyQt4.QtCore import QByteArray


def load_page(br):
  ret = br.load_jquery(True)
  print ret
  return 'Japan' in br.html

br = browser.Browser(
debug_level=4
)
br.load('https://foobar.eu/newton/cgi-bin/cognos.cgi')
br.create_webview()
br.show()

#br.load("https://foobar.eu/newton/cgi-bin/cognos.cgi?b_action=xts.run&m=portal/cc.xts&m_folder=iA37B5BBC0615469DA37767D2B6F1DCF1")
#br.browse()
res = br.load("https://foobar.eu:443/newton/cgi-bin/cognos.cgi?b_action=cognosViewer&ui.action=run&ui.object=/content/folder[@name='DMA Admin Zone']/folder[@name='02. Performance Benchmark Module']/folder[@name='1. Reports']/report[@name='CQM_Test_3_HTML_Heavy_Local_Processing_Final']&ui.name=CQM_Test_3_HTML_Heavy_Local_Processing_Final&run.outputFormat=&run.prompt=true", 1, wait_callback=load_page)


d = str(pyquery.PyQuery(br.html))

if d.find("Japan") > -1:
  print 'We discovered Japan!'
else:
  print 'Japan is nowhere to be seen!'

sleep(10)

The URL in the comments is a page which contains a link to the report. When I click the report by hand the report works (via XHP). However, I can't seem to get it to work via scripting.

The br.load_jquery always returns None.

As a help I have added part of the spynner debug trace when I click the link by hand: http://fpaste.org/97583/13987135/ In firebug I can clearly see the XHP reponse with the string 'Japan' in.

What am I missing?

Was it helpful?

Solution

apparantly replacing the load page function with the following code makes it work:

def load_page(br):
  br.wait(5)
  return 'Japan' in br.html
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top