我需要一个接受这个 ul 的脚本:
<ul id="activitylist">
<li class="activitybit forum_thread">
<div class="avatar"> <img alt="secret team's Avatar" src="images/misc/unknown.gif" title="secret team's Avatar"> </div>
<div class="content hasavatar">
<div class="datetime"> <span class="date">Today, <span class="time">11:25pm</span></span> </div>
<div class="title"> <a class="username" href="member.php/436070-secret-team">secret team</a> started a thread <a href="showthread.php/415403-Allow-VIDEO-Code-missing-in-settings">'Allow [VIDEO] Code' missing in settings</a> </div>
<div class="views">0 replies | 0 view(s)</div>
</li>
</ul>
一ul中有10到15个子li。我需要线程有 0 个回复的每个子 li 的线程名称。我在上面发布了一个示例 li。所以对于那个例子,我需要这个文本:
'Allow [VIDEO] Code' missing in settings
这个 div 有 0 个回复作为文本:
<div class="views">0 replies | 0 view(s)</div>
我有这个示例代码,但它不能正常工作。
<?php
$request_url = 'https://www.vbulletin.com/forum/activity.php';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $request_url); // The url to get links from
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // We want to get the respone
$result = curl_exec($ch);
$sPattern = "/<li class=\"activitybit forum_thread\">(.*?)<\/li>/s";
preg_match_all($sPattern, $result, $parts);
$links = $parts[1];
foreach ($links as $link) {
if (stripos($link, "0 replies") !== false) {
echo $link . "<br>";
}
}
curl_close($ch);
?>