2015-12-19 37 views
1

想知道如何在精确的位置获取网站中的数据;例如在div class“test”中的body中,并在href中的我自己的网站上检索它。使用HTML提取div中的数据

+1

http://stackoverflow.com/questions/17050563/how-to-链接到特定的文本在网页中使用的唯一url – nanocv

+0

也相关:http://stackoverflow.com/q/680562/3345375 – jkdev

回答

1

这叫做刮擦,你可以用很多不同的方法做到。如果有问题的网站是属于你的,你可以很容易地使用JavaScript来获得一个div的内容。例如:

var content = document.getElementById("divID").html; 

你想通过类来检索它,但类名称不一定是唯一的单个元素,这样就行不通了。

如果你没有自己的网站有问题,你仍然可以用PHP解析它获取内容使用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);  
+0

是啊谢谢男人! :) – AndrewBr