From 1a6b9b9d07f454cc3620d5e9d5ef306b29287401 Mon Sep 17 00:00:00 2001 From: Irfan Date: Sat, 11 Sep 2021 02:36:08 +0500 Subject: [PATCH] user profile: fix gender & location parsing when it's not set by the user #358 2.x --- src/Parser/User/Profile/UserProfileParser.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Parser/User/Profile/UserProfileParser.php b/src/Parser/User/Profile/UserProfileParser.php index 411cd168..3769678f 100644 --- a/src/Parser/User/Profile/UserProfileParser.php +++ b/src/Parser/User/Profile/UserProfileParser.php @@ -125,7 +125,9 @@ public function getLastOnline(): ?\DateTimeImmutable */ public function getGender(): ?string { - $gender = $this->crawler->filterXPath('//span[contains(text(), \'Gender\')]/following-sibling::span'); + $gender = $this->crawler + ->filterXPath('//ul[contains(@class, "user-status")]/li/span[contains(text(), "Gender")]/following-sibling::span'); + if (!$gender->count()) { return null; } @@ -156,7 +158,9 @@ public function getBirthday(): ?\DateTimeImmutable */ public function getLocation(): ?string { - $gender = $this->crawler->filterXPath('//span[contains(text(), \'Location\')]/following-sibling::span'); + $gender = $this->crawler + ->filterXPath('//ul[contains(@class, "user-status")]/li/span[contains(text(), "Location")]/following-sibling::span'); + if (!$gender->count()) { return null; }