A
A
Anuar Mendubaev2016-02-29 12:04:33
Parsing
Anuar Mendubaev, 2016-02-29 12:04:33

Parsing by points - title, genre, year, etc. How to implement?

Good day!
Task: to parse data from this site , namely, you need to get a list of games (game name, genre, date, rating) and output as an array. Should look like:

array(
  array(
    'name' => 'Far Cry'
    'genre' => 'action',
    // максимально много информации с сайта
  ),
  array(genre
    'name' => 'Diablo'
    'genre' => 'RPG',
    // максимально много информации с сайта
  )
)

I use the simple-html-dom library, here's what I wrote:
$link = 'http://gamer-info.com/games/';

    $data = file_get_html($link);

    $title = array();
    $genre_arr = array();
    $date_arr = array();

    foreach($data->find('.name') as $name){
      $title['name'][] = $name->plaintext;
    }	
    foreach($data->find('.genre') as $genre){
      $genre_arr['genre'][] = $genre->plaintext;
    }
    foreach($data->find('.dates') as $date){
      $date_arr['date'][] = $date->plaintext;
    }		
    print_r($title);
    print_r($genre_arr);
    print_r($date_arr);

But it outputs:
Array(
     [name] => Array(
                        [0] => Far Cry
                        [1] => Call of Cthulhu
                        и т.д
     )
)
Array(
       [genre] => Array(
                [0] => action/FPS
                [1] => RPG / ужасы
      )
)
Ну и с остальными пунктами точно также. Использую библиотеку simple-html-dom.
Вопрос: Как выводить каждую игру с жанром,датой,оценкой,лого по отдельности?
Что делать?
Спасибо большое за помощь:)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anuar Mendubaev, 2016-03-01
@Frunky

Solved the problem like this:

foreach($data->find('.games-list-v1 .it') as $game){
      $item['title'] = $game->find('.name',0)->plaintext; 
      $item['genre'] = $game->find('.genre',0)->plaintext; 
      $item['date'] = $game->find('.dates',0)->plaintext; 
      $item['logo'] = $game->find('.logo',0)->plaintext; 
      $articles[] = $item;
    }
    print_r($articles);

Thanks to all

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question