Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从驻留在internet上的网页中获取某些元素的值?(PHP或JavaScript)_Php_Javascript_Get_Remote Access - Fatal编程技术网

如何从驻留在internet上的网页中获取某些元素的值?(PHP或JavaScript)

如何从驻留在internet上的网页中获取某些元素的值?(PHP或JavaScript),php,javascript,get,remote-access,Php,Javascript,Get,Remote Access,问题是,我不知道如何从远程互联网页面获取标题内容 例如: 如果网页http:\www.test.com(它是像谷歌或youtube这样的远程页面)包含: <html> <head> </head> <body> <div id = 'temperature'>32</div> </body> </html> 32 可以使用Whitch方法从此页检索

问题是,我不知道如何从远程互联网页面获取标题内容

例如:

如果网页http:\www.test.com(它是像谷歌或youtube这样的远程页面)包含:

<html>
    <head>
    </head>
    <body>
        <div id = 'temperature'>32</div>
    </body>
</html>

32
可以使用Whitch方法从此页检索温度值吗

我需要使用PHP或JavaScript等语言


但是,如果有另一种语言的解决方案,就把它放在这里,它可能会对其他用户有所帮助(他们对Ruby、Perl、Java等语言感兴趣)。

您可以使用cURL和SimpleXML的组合来拉入web请求并将DOM解析为XML

<?php

$URL = "http://yoururl.website";

$ch = curl_init($URL);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);

$domXML = simplexml_load_string(curl_exec($ch));

curl_close($ch);

//Access the dom element you want
print '<pre>';
print_r($domXML);
print '</pre>';
?>

该库可以帮助您在PHP中实现这一点。如果sourceforge链接也不适用于您,则可能是一个合适的替代方案。

您可能希望查看从中获取数据的服务是否具有API。通过这种方式,您可以直接从他们的数据库(在函数允许的情况下)获取信息