0

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?

benhowdle89
  • 36,900
  • 69
  • 202
  • 331

3 Answers3

2

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);
Robin Orheden
  • 2,714
  • 23
  • 24
0

Take a look at strpos for looking in strings...

if (strpos($buffer, '<p class="fact">') !== FALSE) {
  print "Yay";
}
fire
  • 21,383
  • 17
  • 79
  • 114
0

I would check out the HTML parsers mentioned in the answer to this question. As for copyright issues I think it would depend on many factors, including:

  • What are you doing with the content
  • How much of the content are you using
  • What is the copyright on the site you are scraping
Community
  • 1
  • 1
Brian Fisher
  • 23,519
  • 15
  • 78
  • 82
  • just displaying a quote on my website as a bit of fun. Not making any money from it or advertising etc – benhowdle89 Dec 08 '10 at 22:42
  • I'm not a lawyer, but if your just quoting a website its probably ok. Bloggers do that all the time, often taking a paragraph or two from a website and then writing commentary. – Brian Fisher Dec 09 '10 at 01:51