网站内容抓取(1.网页访问_get_contents()函数把整个文件读入一个中 )
优采云 发布时间: 2022-01-20 22:03网站内容抓取(1.网页访问_get_contents()函数把整个文件读入一个中
)
1.网络访问
$content =file_get_contents("");
file_get_contents() 函数将整个文件读入一个字符串。
与 file() 类似,不同之处在于 file_get_contents() 将文件作为字符串读取。
file_get_contents() 函数是将文件内容读入字符串的首选方法。如果操作系统支持,内存映射技术也可用于提高性能。
微信公众平台开关灯的实现:
if (strstr($keyword, "开灯")){
$conten = file_get_contents("http://web.ngrok.aichimantou.com/cgi-bin/test.lua");
$content="已开灯";
}
private function transmitText($object, $content)
{
if (!isset($content) || empty($content)){
return "";
}
$xmlTpl = "
%s
";
$result = sprintf($xmlTpl, $object->FromUserName, $object->ToUserName, time(), $content);
return $result;
}
2.内容提取
// 新建一个Dom实例
$html = new simple_html_dom();
//访问相关网页
$html = file_get_html('http://slashdot.org/');
// 查找id为main的div元素
$main = $html->find('div[id=main]',0);
微信公众平台实现网页内容提取
if (strstr($keyword, "提取")){
include "simple_html_dom.php" ;
$html = new simple_html_dom();
$html = file_get_html('http://web.ngrok.aichimantou.com/design.htm');
//查找id为main的div元素
$content = $html->find('span[id=information]',0)->plaintext;
$content .= $html->find('span[id=gas]',0)->plaintext;
$content .= $html->find('span[id=temper]',0)->plaintext;
$content .= $html->find('span[id=humidity]',0)->plaintext;
}