OGP画像が全て代替イメージになっていたため、サムネイルのスクレイピングを実施
This commit is contained in:
parent
fb84a1d416
commit
e4ef935dd2
@ -28,7 +28,17 @@ class ToranoanaResolver implements Resolver
|
|||||||
|
|
||||||
$res = $this->client->get($url, ['cookies' => $cookieJar]);
|
$res = $this->client->get($url, ['cookies' => $cookieJar]);
|
||||||
if ($res->getStatusCode() === 200) {
|
if ($res->getStatusCode() === 200) {
|
||||||
return $this->ogpResolver->parse($res->getBody());
|
$metadata = $this->ogpResolver->parse($res->getBody());
|
||||||
|
|
||||||
|
$dom = new \DOMDocument();
|
||||||
|
@$dom->loadHTML(mb_convert_encoding($res->getBody(), 'HTML-ENTITIES', 'UTF-8'));
|
||||||
|
$xpath = new \DOMXPath($dom);
|
||||||
|
$imgNode = $xpath->query('//*[@id="preview"]//img')->item(0);
|
||||||
|
if ($imgNode !== null) {
|
||||||
|
$metadata->image = $imgNode->getAttribute('src');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $metadata;
|
||||||
} else {
|
} else {
|
||||||
throw new \RuntimeException("{$res->getStatusCode()}: $url");
|
throw new \RuntimeException("{$res->getStatusCode()}: $url");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user