Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scraping developer data #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ array (
'supported_os' => '4.2 and up',
'content_rating' => 'Everyone 10+',
'whatsnew' => 'What\'s new in version 1.11?[...]',
'author_website' => 'http:\/\/help.mojang.com',
'author_email' => '[email protected]',
'privacy_policy_link' => 'https:\/\/privacy.microsoft.com\/en-us\/privacystatement'
)
```

Expand Down
16 changes: 16 additions & 0 deletions src/Scraper.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ public function getApp($id, $lang = null, $country = null)
'whatsnew' => null,
'video_link' => null,
'video_image' => null,
'author_website' => null,
'author_email' => null,
'privacy_policy_link' => null
);

$info['id'] = $id;
Expand Down Expand Up @@ -186,6 +189,19 @@ public function getApp($id, $lang = null, $country = null)
$info['content_rating'] = $node->filter('div > .htlgb > div')->first()->text();
}
});
$developerInfoNodes = $crawler->filter('.hAyfc > .htlgb > .IQ1z0d > .htlgb > div > .hrTbp');
$developerInfoNodes->each(function ($node) use (&$info) {
$nodeText = $node->text();
$nodeText = str_replace("\xc2\xa0", ' ', $nodeText); // convert non breaking to normal space

if ($nodeText === 'Visit website') {
$info['author_website'] = $node->attr('href');
} elseif ($nodeText === 'Privacy Policy') {
$info['privacy_policy_link'] = $node->attr('href');
} elseif (strpos($nodeText, '@')) {
$info['author_email'] = $nodeText;
}
});
$whatsnewNode = $crawler->filter('[itemprop="description"] > span')->eq(1);
if ($whatsnewNode->count()) {
$whatsnew = $this->cleanDescription($whatsnewNode);
Expand Down
5 changes: 4 additions & 1 deletion tests/resources/app1.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,8 @@
"content_rating": "Everyone 10+",
"whatsnew": "What's new in version 1.11?\nRevamped villages! Discover new villages across different biomes, with job sites, buildings, designs, and construction opportunities. \nEarn the villagers\u2019 trust and explore a refined trading system, with brand new ways to exchange items!\nTerrible new threats! Pillager Outposts are emerging all around the Overworld, preparing their attack. Are you ready to fight back?",
"video_link": "https:\/\/www.youtube.com\/embed\/gcf9FM4TbN4?ps=play&vq=large&rel=0&autohide=1&showinfo=0",
"video_image": "https:\/\/i.ytimg.com\/vi\/gcf9FM4TbN4\/hqdefault.jpg"
"video_image": "https:\/\/i.ytimg.com\/vi\/gcf9FM4TbN4\/hqdefault.jpg",
"author_website": "http:\/\/help.mojang.com",
"author_email": "[email protected]",
"privacy_policy_link": "https:\/\/privacy.microsoft.com\/en-us\/privacystatement"
}
5 changes: 4 additions & 1 deletion tests/resources/app2.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@
"content_rating": "12 \u5c81\u4ee5\u4e0a",
"whatsnew": null,
"video_link": null,
"video_image": null
"video_image": null,
"author_website": null,
"author_email": "[email protected]",
"privacy_policy_link": null
}