Retrieving external content. Load dynamic with jquery into iframe without browser lag - php

I'm create and loading multiple iframes with basic src. But, I have noticed that for each now iframes I create and the src being added with new url for each, the browers locks a bit. So I thought, can I add the page though Ajax instead, using php proxy on the server. I have managed to do this in some extent, but all data does not load. For example, in one specific case a flexslider does not load.
I use
PHP Using phpQuery:
$html = file_get_contents('http://' . $myitem['Web_address']);
$doc = phpQuery::newDocumentHTML($html);
$doc->find('head')->prepend('<base href="'.'http://' . $myitem['Web_address'].'">');
JQUERY: (Note, the iframe is already prepaired with a loader.html document)
$('iframe').contents().find('html').html(data.comp[0]['html']);
A lot does load, but some images do not, can I load ALL content, and how can I acheive this.
Thanks!

Related

php simple html dom and iframe src

require('simple_html_dom.php');
// Create DOM from URL or file
$html = file_get_html('https://www7.fmovies.se/film/hometown-hero.m2r28/6xpjrp');
foreach($html->find('div[id=player]') as $div)
{
foreach($div->find('iframe') as $iframe)
{
echo $iframe->src;
}
}
This is my code and as you see I'm trying to get the src of the iframe under the player div using PHP Simple HTML DOM Parser, can you explain to me why I'm getting a blank page as a result?
Thanks!
UPDATE: After using a javascript switcher addon and disabling javascript, I noticed that the iframe I'm looking for is not loaded. What should I do to get the iframe src?
There are two possible solutions;
Try to figure out how the javascript works, and mock this behavior in your PHP script.
Let the page load in, for example, selenium and then grab the SRC from the iframe using selenium. (https://www.seleniumhq.org/)
Hope this helps

i want to get data from another website and display it on mine but with my style.css

So my school has this very annoying way to view my rooster.
you have to bypass 5 links to get to my rooster.
this is the link for my class (it updates weekly without changing the link)
https://webuntis.a12.nl/WebUntis/?school=roc%20a12#Timetable?type=1&departmentId=0&id=2147
i want to display the content from that page on my website but with my
own stylesheet.
i don't mean this:
<?php
$homepage = file_get_contents('http://www.example.com/');
echo $homepage;
?>
or an iframe....
I think this can be better done using jquery and ajax. You can get jquery to load the target page, use selectors to strip out what you need, then attach it to your document tree. You should then be able to style it anyway you like.
I would recommend you to use the cURL library: http://www.php.net/manual/en/curl.examples.php
But you have to extract part of the page you want to display, because you will get the whole HTML document.
You'd probably read the whole page into a string variable (using file_get_contents like you mentioned for example) and parse the content, here you have some possibilities:
Regular expressions
Walking the DOM tree (eg. using PHPs DOMDocument classes)
After that, you'd most likely replace all the style="..." or class="..." information with your own.

How do I use URLs of images from a text file in a javascript slideshow?

I'm creating a slideshow where I'm displaying images based on their urls. I've used PHP to extract the image urls from web pages and I've used JavaScript to display them in a slideshow format. Only thing is, the first picture takes a lot of time to load so I decided to cache the urls by storing them in a text file, but I don't know how to read the urls from the text file in my JavaScript bit?
Could anyone point me in the right direction as to how I should proceed. I couln't find anything helpful online.
My JS code is like this:
<script language="JavaScript1.1">
var slideimages=new Array()
slideshowimages("<?php echo join("\", \"", $image_urls); ?>") <--this is where I was initially echoing the array or image urls from php, but it proves slow for the first few images
function slideshowimages(){
for (i=0;i<slideshowimages.arguments.length;i++){
slideimages[i]=new Image()
slideimages[i].src=slideshowimages.arguments[i]
}
}
var slideshowspeed1=30000
var whichimage1=0
function slideit1(){
if (!document.images)
return
document.images.slide1.src=slideimages[whichimage1].src
if (whichimage1<slideimages.length-1)
whichimage1++
else
whichimage1=0
setTimeout("slideit1()",slideshowspeed1)}slideit1()
</script>
Thanks!
Why are you pulling from an external website? You generally will get a lot more speed if you pull them locally. I do believe that once it pulls the images once or so, it will cache for users when it shows up again. What you could do is to use that list you pull and create the images hidden on the page so they load with the page. Then when going through the slideshow, the user should have had time to cache the images and the slideshow will have sped up.
Just make a CSS class known as hidden and visability:hidden;it. Most browsers will still try to load the data.

Loading a certain area of HTML from an external domain webpage into a div

I'm currently designing a website for a company that uses an external site to display information about its clients. Currently, their old website just puts a link to the external profile of each client. however with this rebuild, I wondered if there was any way to load a specific portion of the external site onto their new page.
I've done my research, and I've found it's possible using jQuery and AJAX (with a bit of a mod) but all the tutorials relate to a div tag being lifted from the external site then loaded into the new div tag on the page.
Here's my problem: after reviewing the source code of the external source, the line of HTML I want isn't contained in a named DIV (other than the master wrap and I can't load that!)
The tag I need is literally: <p class="currentAppearance"> data </p>
It's on a different line for each profile so I can't just load line 200 and hope for the best.
Does anyone have any solution (preferably using php) that searches for that tag on an external page and then loads the specific tag into a div?
I hope I've been clear I am quite new to all this back end stuff!
First I would use to grab the content from the webpage:
http://www.php.net/manual/en/curl.examples-basic.php
$url = 'http://www.some-domain.com/some-page';
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$htmlContent = curl_exec($curl);
curl_close($curl);
Then using DomDocument (http://ca3.php.net/manual/en/book.dom.php) you'll be able to access the right div based on its ID for instance.
$doc = new DOMDocument();
$doc->loadHTML($htmlContent);
foreach ($pElements as $pEl) {
if ($pEl->getAttribute('class') == 'currentAppearance') {
$pContent = $pEl->nodeValue;
}
}
$pContent is now set with the content of the paragraph with class currentAppearance
You could use xpath syntax to grab it out of the document.

phpQuery - make php script wait until iframe content has loaded

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.
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!

Categories