dswsl2016 2010-12-08 22:13
浏览 116
已采纳

PHP cURL抓取特定的HTML

I'm using this PHP:

<?php

$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'http://www.notrly.com/jackbauer/');
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);

if (empty($buffer))
{
    print "Not today";
}
else
{
    print $buffer;
}
?>

There is a p tag with class "fact" in the source that i want to extract and display! How do i do it? Also is it against copyright if i use this to grab someone else HTML off of their site?

  • 写回答

3条回答 默认 最新

  • douli1872 2010-12-08 22:21
    关注

    If you want to use cURL, then download the page and use a DOM-parser like:

    http://simplehtmldom.sourceforge.net/

    Or you could just do something like this:

    include_once('simple_html_dom.php');
    
    $dom = file_get_html('http://www.notrly.com/jackbauer/');
    
    foreach($dom->find("div.head div.fact p.fact") as $element)
        die($element->innertext);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办