Php 我使用简单的HTMLDOM库获得的设备信息
下面是代码的较短部分Php 我使用简单的HTMLDOM库获得的设备信息,php,html,Php,Html,下面是代码的较短部分 include('simple_html_dom.php'); //load HTML file $html = file_get_html('www.csfd.cz-film-2294-vykoupeni-z-veznice-shawshank-videa-.txt'); //with simple_html_dom i search for data-truncate*="60" $ret = $html->find('span[data-truncat
include('simple_html_dom.php');
//load HTML file
$html = file_get_html('www.csfd.cz-film-2294-vykoupeni-z-veznice-shawshank-videa-.txt');
//with simple_html_dom i search for data-truncate*="60"
$ret = $html->find('span[data-truncate*="60"] a');
$actors = array();
//i just print down all result of this search with <span data-truncate="60">
foreach ($ret as $reziser) {
$rezia[] = $reziser->innertext;
}
echo "<br/> REZIA: <br/>";
echo "$rezia[0] <br/>";
echo "$rezia[1] <br/>";
echo "$rezia[2] <br/>";
echo "$rezia[3] <br/>";
echo "$rezia[4] <br/>";
include('simple_html_dom.php');
//加载HTML文件
$html=file_get_html('www.csfd.cz-film-2294-vykopeni-z-veznice-shawshank-videa-.txt');
//使用simple_html_dom,我搜索数据截断*=“60”
$ret=$html->find('span[data truncate*=“60”]a');
$actors=array();
//我只是打印了这个搜索的所有结果
外汇($ret as$reziser){
$rezia[]=$reziser->innertext;
}
回声“
雷齐亚:
”;
回声“$rezia[0]
”;
回声“$rezia[1]
”;
回声“$rezia[2]
”;
回声“$rezia[3]
”;
回声“$rezia[4]
”;
,我也试着用英语评论一下。我的问题是,更多的事物具有相同的跨度()
如果你检查这个页面的HTML()并搜索,你会发现类似的东西:问题是更多不同的类别使用相同的跨度(Režie,Předloha,Scénář,Kamera,Hudba)。现在我只搜索这个跨度,可以打印出来或保存到数据库,但我需要根据这些类别来确定搜索结果(这部分代码中的每一个都是类别名称,我需要在它们之间划分结果)
我希望你知道我在说什么。无论如何,感谢你帮助我解决我的问题您可以用..parent()函数获得html元素的父元素 你可以这样做:
foreach ($ret as $reziser) {
//get the <div> wrapping the <span> wrapping the <a>
$parent = $reziser -> parent() -> parent();
//get the h4 element containg the category
$category_element = $parent -> find('h4');
//get the category
$category = $category_element[0] -> innertext;
//use the category as the key of your array enters
$rezia[$category] = $reziser -> innertext;
}
foreach($ret as$reziser){
//把包装拿过来
$parent=$reziser->parent()->parent();
//获取包含类别的h4元素
$category_element=$parent->find('h4');
//获取类别
$category=$category_元素[0]->innertext;
//使用类别作为数组的键
$rezia[$category]=$reziser->innertext;
}
这只是一个如何获取类别的示例。我不太明白您真正想要的是什么,请根据您的需要调整代码
霍顿ěětěstí