How to: Web Scrape/ Parse a website and return content

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
medit
Forum Newbie
Posts: 1
Joined: Mon Apr 07, 2008 11:44 pm

How to: Web Scrape/ Parse a website and return content

Post by medit »

Hello all,
I'm quite a newbie to the php language. But was hoping after more than a few hours of search online if someone could help me with the following with some working sample code:

1. I have a website that I want to parse/scrape.
2. I have a text pattern.

Question:
1. Does anyone have an working sample code that I can take a look at?

any help would be appreciated.
User avatar
Kadanis
Forum Contributor
Posts: 180
Joined: Tue Jun 20, 2006 8:55 am
Location: Dorset, UK
Contact:

Re: How to: Web Scrape/ Parse a website and return content

Post by Kadanis »

You could try

Code: Select all

 
 
$page_content = file_get_contents('http://www.url-here.tld');
 
...#parsing code here
 
 
I've seen it used before to get web site code and parse it. If that's what you're after. I think the only limitation is that the PHP server option allow_url_fopen must be on for this to work.

The alternative (although I've never done this) which I turned up through 1 google search, is to use Curl.

http://wiki.dreamhost.com/index.php/CURL
Post Reply