/    Sign up×
Community /Pin to ProfileBookmark

Parse data from another website (preg_match & preg_match_all)

Hello everyone!

Im having some difficulties with parsing data from another website. I can get the first peace out of it, but when trying to get out the rest of the pieces from the first cut, things stop working as they did. Heres the code:

[code=php]$html = file_get_contents(“http://www.avto.net/_DEALER/results.asp?broker=12430&star=&izpis=1&oglasrubrika=7&oblika=0&subKAT=0&model=”);
$pattern = ‘/<div class=”contentwrapper”>(.*?)</div>/s’;
//$pattern = ‘/<form id=”compare”.*?(.*?)</form>/s’;
preg_match($pattern, $html, $data);
$form = ‘/<form.*?>(.*?)</form>/s’;
preg_match($form, $data[1], $cut);

$pattern2 =’/<table width=”730″ cellspacing=”0″ cellpadding=”0″ border=”0″>(.*?)</table>/s’;
preg_match_all($pattern2, $cut[1], $tabele);

echo “<pre>”;
print_r($cut[0]);
echo “</pre>”;

echo “<br />”;
echo “<br />”;

echo “<pre>”;
print_r($tabele);
echo “</pre>”;

[/code]

I need contentwrapper class, but I have to clean it up a little so it would show only the table with car pars, no extra text or page numbers needed. The first preg_match is working well, but when trying to get all these tables -> <table width=”730″ cellspacing=”0″ cellpadding=”0″ border=”0″>(.*?)</table>, the result is none. Any tip is welcome. I also tried with “Simple HTML DOM parser” who has the function file_get_html() (if you are familiar with), but its way to much that I need, I need to get just the list of items from first page (not from all 30 pages..) to present them on my page.
Any help is very welcome.

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @Orange06 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...