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
Related
I started learning php. How can I find video source url with php. Can someone tell me how to get video url with simple_html_dom? For example how to find a video source url from a website?
Thank you
First of all, you need to understand how you can fetch an HTML document on a site. Everything you see in the browser consists of HTML and CSS. When you fetch a HTML document from a page with PHP, you get whatever is on the screen at that moment. So if a content is loaded into the page later using an Ajax call like below, you can't get it directly from the page.
function loadVideoURL() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.status == 200) {
document.getElementById("videosrc").innerHTML = this.responseText;
}
};
xhttp.open("GET", "get_video_url.php", true);
xhttp.send();
}
In the current situation, suppose that the video urls included in the HTML document in the first place.
First Download latest version of simplehtmldom from here. This is the PHP Class to manipulate HTML in easy way and this library requires minimum PHP 5. Create a file which name is simplehtmldomparser.php in main directory of your project and include it using code below to your main php code.
<?php
include 'simplehtmldomparser.php';
?>
This code block will load the class to your main PHP file. Now, you want to fetch video url from the page.
<?php
$html = file_get_html('http://www.videos.com/');
/* This line will fetch HTML document from the site that you wrote. */
?>
Now, you have the html document in $html variable. You need find video tags in HTML document. For example, If fetched page uses a <video> tag for videos, you can get the video urls as follows.
<?php
foreach($html->find('video') as $element){
echo $element->src . '<br>';
}
?>
Here is another example that might work for your project. For example you want to jump another video in the website, fetch all <a> tags and get their hrefs and use the $html = file_get_html($newlyfetchedanchor); again. To fetch all <a> tags from the current $html use code below.
<?php
foreach($html->find('a') as $element){
echo $element->href;
}
?>
There are more useful functions in the class and you can find here.
Id like to update the 'src' attribute of an img tag using Simple HTML DOM. Ive got his at the top of the php file (join.php) which contains the img file:
include_once("simplehtmldom/simple_html_dom.php");
$htmldomOb = file_get_html('join.php');
$htmldomOb->find('img[id=imgtapchat]', 0)->src = './tapchat/clss_tapcht-1.php';
echo $htmldomOb;
This works but outputs the entire page again since i read in the entire page dom object. How can i just update the image src similar to how it is done in jQuery - As it says in the SimpleHTMLDOM site docs
Find tags on an HTML page with selectors just like jQuery
With thanks
I use PHP Dom extension to rewrite PHP Simple Dom, just finished. You can try it here.
http://shinbonlin.github.io/html-parser/
I'm trying to 'iframe' a div using PHP / DOM instead showing the whole page, but I am having difficulties as the Div contains a custom google map and even when I try to show the entire page I am not able to make the map load. How is it possible to do it?
Link : http://satbeams.com/footprints?beam=5491
Div Id : "map_container"
What I have tried so far :
<?php
set_time_limit(0);
ini_set('memory_limit', '-1');
ini_set('display_errors',false);
include 'includes/dom.php';
$html = file_get_contents('http://satbeams.com/footprints?beam=5491');
$map = $html->find('div[map_container]');
echo $map;
?>
Thanks
file_get_contents returns a pure string, not an dom object you may manupilate. So have a look at http://php.net/manual/en/domdocument.loadhtml.php
A Google Map is mainly rendered via a javascript-API, so there isn't any existing iframe in the html markup that you could extract. You would have to parse the json data included in the page, and rebuild the map.
Be sure to not violate any copyrights!
I've been working on this for about four hours and have been all over the internet trying to understand it, so please be gentle.
I'd like to display a div from an external source on my php page. I've tried usingfile_get_dom, simplexml_load_file, file_get_contents with preg_match_all, then printed them on my page, but they don't work. cURLing is over my head from what I have seen and can't understand any of it, but I've been told it is the best way to do it. They all result in various errors when all I want is to grab the contents of an external div. What should I do?
An example would be scraping the div id='hmenus' on this page, then displaying it on my local page.
Thanks!
If cURL is over your head then perhaps try Simple HTML DOM
$html = file_get_html($url);
echo $html->find('div[id=hmenus]', 0);
I'm trying to parse a HTML page where the majority of the content is contained in javascript. When I use the Chrome development tools I can see that the div class I'm trying to grab the content from is called div class=doodle-image. However when I either view the page as a source or try to grab it with php:
<?php
include_once('simple_html_dom.php');
$html = new simple_html_dom();
$html->load_file('http://www.google.com/doodles/finder/2012/All%20doodles');
$doodles = $html->find('.doodle-image');
echo $html;
?>
It returns the frame of the page but contains none of the divs or content. How can I grab the full content of the page?
That's because the element is empty when your PHP client fetches it, Google is loading in a JSON-object with JavaScript to populate the list of doodles. It does a Ajax-request to this page, and probably you can too.