我想使用简单的html dom解析器PHP通过标题中的特定文本获取链接
HTML代码
<h3 class="title"><a href="0.html" class="title"> keyword1 </a></h3>
如果标题为“ keyword1”,如何获取链接?
我的代码
$html = file_get_html($url);
foreach($html->find('h3[class=title]') as $e){
if(isset($e)){
foreach($e->find('keywords1') as $ee)
foreach($html->find('a') as $eee){
$d = $eee;
print_r ($d)."<br>";
}
此代码查找a
包含以下内容的标签keyword1
$html = file_get_html($url);
foreach($html->find('h3[class=title] a[plaintext*=keyword1]') as $a)
echo $a->href . "\n"; // 0.html
为了确保它是您想要的,您可以另外进行测试
trim($a->innertext) == 'keyword1'
UPD:
如果我正确理解了你想要什么
echo substr($url, 0, strrpos($url, '/')) . '/' . $a->href;
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句