I am making a website in which the user will provide with URL of some other page and the code will read (not open) it and extract a part of the page.
Say, I provide URL for this page, and I get the question header of the page.
How can I do that.?
I tried using AJAX, creating object of HTTPRequest
, but was not able to read a particular part of the page. (say innerHTML of some #id)
there is a php lib made for this and its called PHP Simple HTML DOM Parser
// Create DOM from URL or file
$html = file_get_html('http://www.google.com/');
// Find all images
foreach($html->find('img') as $element)
echo $element->src . '<br>';
// Find all links
foreach($html->find('a') as $element)
echo $element->href . '<br>';
Syntax:
file_get_contents("URL");
Example:
echo file_get_contents('http://www.stackoverflow.com');