Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.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
Php 使用简单的HTMLDOM获取特定的文本区域 2015-02-21 19:51:38上传, 大小(7.37 MB),由_Php_Html_Parsing_Simple Html Dom_Scrape - Fatal编程技术网

Php 使用简单的HTMLDOM获取特定的文本区域 2015-02-21 19:51:38上传, 大小(7.37 MB),由

Php 使用简单的HTMLDOM获取特定的文本区域 2015-02-21 19:51:38上传, 大小(7.37 MB),由,php,html,parsing,simple-html-dom,scrape,Php,Html,Parsing,Simple Html Dom,Scrape,您好,我是简单HTMLDOM的新手 我只想刮这个动态大小区域->(7.37 MB) 我正在使用这个代码 <font class="detDesc">Uploaded <b>2015-02-21 19:51:38</b>, Size (7.37 MB), ULed by <a class="detDesc" href="/user/FirstUploads/" title="Browse FirstUploads">FirstUploads

您好,我是简单HTMLDOM的新手

我只想刮这个动态大小区域->(7.37 MB)

我正在使用这个代码

<font class="detDesc">Uploaded <b>2015-02-21 19:51:38</b>, 
 Size (7.37 MB), ULed by 
 <a class="detDesc" href="/user/FirstUploads/"
 title="Browse FirstUploads">FirstUploads</a>
</font>

但它给了我这个->(2015-02-21 19:51:38)

因为我只需要->(7.37 MB)


有什么建议吗

您需要CSS和正则表达式的组合:

<?php 
 include 'simple_html_dom.php'; 
 $html = file_get_html('http://some site.com/');

 foreach($html->find('font[class=detDesc] b') as $size2) 
 { 
 $size[]=  $mysqli->real_escape_string(trim($size2->plaintext)); 
 echo $size2->plaintext.'<br>';
 } 
?>

这不是您的选择器:
font[class=detDesc]b
只是得到了粗体标记,您要么需要包装您的尺码然后得到它,要么只使用
font[class=detDesc]
然后对
尺码进行拆分
谢谢@Pete我可以得到代码示例作为您的建议吗?很抱歉,我刚接触简单的HTMLDOM。我已经有一段时间没有接触php了,但这可能会有所帮助:我使用这段代码。。foreach($html->find($font[class=detDesc]')为$size2){$size[]=explode(“,”,trim($size2->plaintext));$size=substr($size[1],5,-1);echo$size2->plaintext.
”;}但它给了我->上传的2015-02-21 19:51:38,大小7.37 MB,因为我只需要7.37 MB,请尝试以下链接:
$desc = $html->find('.detDesc', 0);

if(preg_match('/\d+\.\d{2} [MKG]?B/', $desc->text(), $m)){
  echo $m[0];
}