views:

475

answers:

3

Hello !

I'm trying to extract some information from a webpage using php cURL+preg_match or any other function but for some reasons it doesn't work at all . For example from this page http://www.foxtons.co.uk/search?location_ids=1001-29&property_id=712128&search_form=map&search_type=LL&submit_type=search I want to extract the title which is "4 bed house to rent, Caroline Place, Bayswater, W2", the price which is "2,300" and the description which starts at "This fantastic..." and ends at "(Circle and District Lines). " I tried to use php cURL + dom but I'm getting a lot of errors like this "htmlParseEntityRef: expecting ';' in Entity, line: 243" and no result displayed

Also I tried to use preg_match or preg_match_all but doesn't work either .

A very basic example would be highly appreciated !

thank you !

A: 

I cannot give a high enough recommendation for HTMLsql:

http://www.jonasjohn.de/lab/htmlsql.htm

This puppy has saved me many times in too many ways to count.

Jesse Kochis
+1  A: 

You could try whether the Simple HTML DOM parser is more fault tolerant.

And take note of the Terms & Conditions of the site you are scraping.

Pekka
A: 

A very basic example would be highly appreciated

To answer the regex part:

preg_match('!<title>(.*)</title>!s', '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
<title>

            4 bedroom


        house


    to rent in Caroline Place, Bayswater, W2 through Foxtons (Property to rent)</title>
<meta name="keywords" content="Houses" />', $matches);
print_r($matches);

/* output:
Array
(
    [0] => <title>

            4 bedroom


        house


    to rent in Caroline Place, Bayswater, W2 through Foxtons (Property to rent)</title>
    [1] => 

            4 bedroom


        house


    to rent in Caroline Place, Bayswater, W2 through Foxtons (Property to rent)
)
*/

The s at the end of the regex puts the parser into something (inaptly) called single-line mode.

webbiedave
thank you very much for your help . I successfully made a script to extract the information that I needed but I still have some issues with the price . I have this : preg_match('!<noscript>\(.*), <\/noscript>!s', $itemPage , $matches); $text = $matches['1'];//clean title by html tags $price = strip_tags($text); echo $price;The $itemPage is the html content .
Michael