Search code examples
phpscreen-scrapingmining

Data Scraping with php


I want to scrape data using php. But I don't understand where im wrong. I want to receive "15,50 TL" text. Thank you

<?php

function find($start, $close, $where)
{
    @preg_match_all('/' . preg_quote($start, '/') .
    '(.*?)'. preg_quote($close, '/').'/i', $where, $m);
    return @$m[1];
}

$url = "https://www.bynogame.com/Knight-Online/Gold-Bar";

$fulldata = file_get_contents($url);

$akara = find('<td align="center" nowrap="nowrap">','<form name="urunayrinti38154"></form></td>',$fulldata);

print_r($akara);

?>

Solution

  • The problem is that the $start and $close strings are nowhere to be found in the page.

    There is a <td align="center" nowrap="nowrap">, with 2 spaces between the td tag name and the align attribute, and there's a <form name="urunayrinti38154"> string without the rest.

    IMHO, a better approach is to use either a DOM parsing library, such as Symfony's DomCrawler component, or PHP's own XML Manipulation functions, such as DOMDocument::loadHTMLFile().