【发布时间】:2014-06-01 04:23:16
【问题描述】:
如果“标签”是正确的术语,我不是,但我必须从这个跨度中获取“数据时间”值到一个数组中。如何使用简单的 html dom 来获取它们?
这是我试图摆脱“数据时间”的跨度。
include('../simpleHtmlDom/simple_html_dom.php');
// Put the Twitters username here
$user = "yadayada";
$html = file_get_html("https://twitter.com/$user");
$ret = $html->find('div[class=ProfileTweet-contents]');
$ret = $html->find('p[class=ProfileTweet-text js-tweet-text u-dir]');
/// tries to get the time code but does only gets the span
$date = $html->find('span[class=js-short-timestamp js-relative-timestamp]', 0);
$DoesNotWork = $html->find( "data-time", 0 );
echo $ret[1]; // get's a users tweet.
echo $DoesNotWork;
日期的结果
<span class="js-short-timestamp js-relative-timestamp"
data-time="1401528672"
data-long-form="true">
15h
</span>
我认为它是这样的,但这段代码不起作用。 $html->find("数据时间", 0);
【问题讨论】:
-
可以使用正则表达式,preg_match("/data-time=.*"/", $input_line, $output_array);
-
您说的是属性,而不是标签。
标签: html simple-html-dom