dousuowu4610 2012-12-21 19:51
浏览 13

PHP5解析(部分)菜鸟的字符串帮助

I have a unique item on an html page. I have been able to parse most of the items, since they are not using combined processed to parse one item.

I have a tricky item to parse:
- it is a list item, inside a DIV, which is unique (ld_sec_col)
- the UL class is not unique (ld_details_list)
- it is NOT a specific list item number (e.g. not the 3rd or 4th, that) always changes
- it IS found after unique text
- my problem is combining the techniques used to get it, without an error, and i am braindead.

Here is the snippet:
#####
   <div class="ld_sec_col">
    <ul class="ld_details_list">
    <li><span class="ld_lbl">Exterior:</span> Brick</li>
    <li><span class="ld_lbl">Living style:</span> Bungalow</li>
    <li><span class="ld_lbl">Property type:</span> Detached</li>
    <li><span class="ld_lbl">Sewer system:</span> Sewers</li>                   </ul>
    </div>
### End Snippet ###

So here I am trying to locate the unique text, (Property type:) and grab the text immediately following it:

I am obviously misusing FIND. And I am reduced to trial and error. But I would like to have this script done before Christmas. It is the last item....

### START PHP CODE ###

$tempproptype = trim($entry->find('.ld_sec_col', 0)->plaintext);
if(preg_match('/^Property type: (.*),/', $tempproptype, $matches))
$propertytype = $matches[1];

### ENDPHP CODE ###
  • 写回答

4条回答 默认 最新

  • douyan8413 2012-12-21 22:32
    关注

    Replace the regex

    '/^Property type: (.*),/'
    

    with

    '~Property type:</span>(.*)</li>~Ui'
    
    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法