1

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.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
AndrewBr
  • 67
  • 7

1 Answers1

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