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 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试