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.
Related
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'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!
Hi I am currently doing my website to pull all instagram photo into my web.
this is my code:
<div id="instafeed"></div>
<script type="text/javascript">
new Instafeed({
get: 'tagged',
tagName: 'awesome',
clientId: 'xxx',
image_size: 'standard_resolution',
}).run();
</script>
How do I get the url/path of the photo that i pulled inside my site?
Is it something about JSON? but i dont know what is it anyone can give me a hint?
Thanks!
You could use a webcrawler to pull the information you need from website.
Here is a nice tutorial. You need to specify the url and the desired html tag.
<?php
include_once('simple_html_dom.php');
$html = new simple_html_dom();
$html->load_file($target_url);
foreach($html->find('img') as $link)
{
echo $link->href."<br />";
}
Moreover you should look over cURL to improve you webcrawler.
EDIT:
#youaremysunshine
the code above is from the tutorial i suggested you look at. 'simple_html_dom.php' is a file that you need to download (you can find it in the tutorial) in order to use its functions.
So, after you include the file, you simply create a new simple_html_dom object and call the function load_file() with the desired url as a parameter. $html->find('img') looks for the <img> tag from the given page. Try to read the tutorial a few times and you may need to look up for part 2. Go to the website with the desired image and inspect element to see wich element you need to use for the find() function (the parameter may also contain the class/id of the searched element).
I wanted to know if its possible to make this code search every page from that website so it pulls every image src from all pages. Currently it will only pull the image src from that one page. I tried using a while loop but it only repeats the same results from the main page over and over. Any help would be great.
<?php
include_once('simple_html_dom.php');
//show errors
ini_set('display_errors', true);
error_reporting(E_ALL);
$html = file_get_html('http://betatv.net/');
$result=($html);
while($html = ($result)) {
// find the show img and echo it out
foreach($html->find('.entry-content') as $cover_img)
foreach($cover_img->find('img') as $cover_img_link)
//echo the images src
echo $cover_img_link->src .'<br>';
echo '<br>';
}
// clean up memory
$html->clear();
unset($html);
?>
Proof that i own betatv.net i added a link to this question on the front page.
Here is a nice example of a page crawler:
How do I make a simple crawler in PHP?
You just need to use your piece of code for each link it finds.
Also if you own this page I bet there is a better way to find all images instead of crawling it from frontend.
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.