0

I'm using the phpQuery library (http://code.google.com/p/phpquery/) to parse web pages but have stumbled across a problem getting sites that use Ajax to display all the content.

I have worked out that I can get all the content if I load it in to an iframe (the code below works):

$temp = phpQuery::newDocumentHTML('<iframe src="" id="test">a</iframe>')->find('iframe[id=test]')->attr('src', 'http://www.example.com/');
echo $temp;

BUT, my question is, how can I get my PHP script to wait until the iframe has loaded before proceeding?

Below is the jQuery equivalent but I was wondering if anybody knows how to do the equivalent using phpQuery?

$(iFrame).attr('src', 'http://www.example.com');
$(iFrame).load(function(){
    alert("Loaded");
});

Thanks in advance.

1
  • 1
    phpQuery =/= jQuery, phpQuery won't load iframe SRCs. The iframe will remain empty. Commented Aug 13, 2011 at 10:30

1 Answer 1

2

BUT, my question is, how can I get my PHP script to wait until the iframe has loaded before proceeding?

This is not how PHP-side HTML parsing works. phpQuery just parses the HTML code, it doesn't do anything with it - like load and/or render iframes, or run JavaScript events.

There is probably a way to do what you want to do - if you tell us what that is!

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your response @Pekka. An example: say I wanted to parse the scores from nfl.com (in the grey bar directly below the main navigation). I currently can't get the value of this bar without loading it in an iframe as the scores are loaded by ajax. But, when I load the page into an iframe (as shown in the code from my original post) the script doesn't wait for the iframe to load completely before it continues with its processing. Do you know of a method to load a webpage complete with its Ajax content into a variable for parsing with phpQuery? Thanks again.
@user that is not possible at all using phpQuery alone - it will only parse HTML, but not execute JavaScript. Maybe this helps: Execute javascript in PHP

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.