dpquu9206 2016-05-24 10:16 采纳率: 0%
浏览 66
已采纳

使用简单的Html dom解析器通过特定搜索文本获取链接

i want to get a link by specific text in title, using simple html dom parser PHP

html code

<h3 class="title"><a href="0.html" class="title">  keyword1 </a></h3>

how to get link if title is "keyword1" ?

my code

$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>";
}
  • 写回答

2条回答 默认 最新

  • doutu7123 2016-05-24 10:39
    关注

    This code finds a tag containing keyword1

    $html = file_get_html($url);
    foreach($html->find('h3[class=title] a[plaintext*=keyword1]') as $a) 
       echo $a->href . "
    ";  //  0.html
    

    To sure that it is what you are looking for, you can additionally test that

    trim($a->innertext) == 'keyword1'
    

    UPD:

    if I correcty understood what you want

    echo substr($url, 0, strrpos($url, '/')) . '/' . $a->href;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来