Just wondering how I can fetch the data in a website at a precise position; for example in body in div class"test" and retrieve it on my own website in a href.
Asked
Active
Viewed 705 times
1
-
1http://stackoverflow.com/questions/17050563/how-to-link-to-specific-line-of-text-in-page-using-only-url – nanocv Dec 19 '15 at 19:47
-
Also related: http://stackoverflow.com/q/680562/3345375 – jkdev Dec 20 '15 at 00:35
1 Answers
1
This is called scraping and you can do it in a lot of different ways. If the website in question belongs to you, you can easily use javascript to get the content of a div for example:
var content = document.getElementById("divID").html;
You want to retrieve it by class, but class names are not necessarily unique to individual elements, so that won't work.
If you don't own the website in question you can still get the content by parsing it with PHP using the curl command:
// create curl resource
$ch = curl_init();
// set url
curl_setopt($ch, CURLOPT_URL, "example.com");
//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $output contains the output string
$output = curl_exec($ch);
// close curl resource to free up system resources
curl_close($ch);

cantelope
- 1,147
- 7
- 9