替换数组中的元标记而不是选择器,以便在php中进行解析?
我是PHP开发的新手,我想解析元标记的内容,但我不知道如何继续 我有一段代码,允许我解析这些元素的内容替换数组中的元标记而不是选择器,以便在php中进行解析?,php,Php,我是PHP开发的新手,我想解析元标记的内容,但我不知道如何继续 我有一段代码,允许我解析这些元素的内容#band,ul[style='height:400px;']选择器 // Pull in PHP Simple HTML DOM Parser include("simplehtmldom/simple_html_dom.php"); // Settings on top $sitesToCheck = array( // id is the page
#band
,ul[style='height:400px;']
选择器
// Pull in PHP Simple HTML DOM Parser
include("simplehtmldom/simple_html_dom.php");
// Settings on top
$sitesToCheck = array(
// id is the page ID for selector
array("url" => "http://www.arsenal.com/first-team/players", "selector" => "#squad"),
array("url" => "http://www.liverpoolfc.tv/news", "selector" => "ul[style='height:400px;']")
);
$savePath = "cachedPages/";
$emailContent = "";
// For every page to check...
foreach($sitesToCheck as $site) {
$url = $site["url"];
// Calculate the cachedPage name, set oldContent = "";
$fileName = md5($url);
$oldContent = "";
// Get the URL's current page content
$html = file_get_html($url);
// Find content by querying with a selector, just like a selector engine!
foreach($html->find($site["selector"]) as $element) {
$currentContent = $element->plaintext;;
}
// If a cached file exists
if(file_exists($savePath.$fileName)) {
// Retrieve the old content
$oldContent = file_get_contents($savePath.$fileName);
}
// If different, notify!
if($oldContent && $currentContent != $oldContent) {
// Build simple email content
$emailContent = "Hey, the following page has changed!\n\n".$url."\n\n";
}
// Save new content
file_put_contents($savePath.$fileName,$currentContent);
}
// Send the email if there's content!
if($emailContent) {
// Sendmail!
mail("me@myself.name","Sites Have Changed!",$emailContent,"From: alerts@myself.name","\r\n");
// Debug
echo $emailContent;
}
HTML DOM解析器在以下位置可用:
但是,我的问题是,我想更改此代码,以获取meta标记中的注释数和rates内容。还有,别忘了,我是完全的新手
这里是meta标记,我只想从中提取评论的数量:
<meta item="desc" content="Comments:645">
<meta item="rates" content="Rates:112">
几天来,我一直在扯他的头发,但我没有成功!
请帮帮我
非常重要的精度,我要提取的元标记不在文档的标题中,而是在正文中强>
我解释得很清楚?如果您需要更多信息,请咨询我(仅限于我的新手技能;-)没有帮助!?为什么,错误的解释?哦,这个元不是在html文档的头中,而是在正文中!!!我认为这很重要