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条)

报告相同问题?

悬赏问题

  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?