Answer the question
In order to leave comments, you need to log in
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',
// максимально много информации с сайта
)
)
$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);
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
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);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question