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?

3 Answers 3

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);
Sign up to request clarification or add additional context in comments.

2 Comments

excellent, once again, is that against some sort of copyright>
From what I can see, there is no copyright visible on the page. So I assume that it is publicly available.
0

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

if (strpos($buffer, '<p class="fact">') !== FALSE) {
  print "Yay";
}

Comments

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

2 Comments

just displaying a quote on my website as a bit of fun. Not making any money from it or advertising etc
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.