How to grab text from a website with cURL?

rnc505

Regular Member
Joined
Oct 28, 2008
Messages
229
Reaction score
112
How do I use cURL to harvest the text of a website, say the blog entry titles of a Blogspot blog....

I know the text (in the source) before a title is:

Code:
<h3 class="post-title">
and after the title it is:
Code:
</h3>


How would I go about doing this? Thanks a lot!
 
These tutorials that may help you:

Code:
http://stackoverflow.com/questions/26947/how-to-implement-a-web-scraper-in-php
http://www.oooff.com/php-scripts/basic-curl-scraping-php/basic-scraping-with-curl.php
 
You can always use wget then grep, or if wget is blocked, lynx --source works too. I know curl can do more, and I molest it daily, but sometimes I prefer simpler too :)
 
you can either turn it into well-formed xml and then traverse the tree or use a regex. in either case, it's beyond the scope of this forum. you will have better luck on a PHP or other programming forum.
 
Using Perl and Mechanize would do the trick as well :)
Been using Mechanize a lot lately and it rocks!
 
I'm a heavy Mechanize user as well and highly recommend it if the page doesn't have JavaScript
 
Unless I'm missing something here all you need is 'substr' between the position of the start and end of the title, no?
 
Here's the proper and easy way of doing it

Code:
http://nytemarez.com/scraping-with-php-and-dom/
 
PHP:
<?php
//get the page with curl; look it up. php.net/curl_setopt

preg_match_all('@<h3 class="post-title">(.*)<\/h3>@is',$page,$matches);

$titles = $matches[1];

?>

untested. may need more tweaking
 
Back
Top