Skip to content

Commit d51d462

Browse files
committed
fix:title获取失败导致程序异常问题
1 parent fe13a51 commit d51d462

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/Import/ArticleImport.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,13 @@ public static function getBodyTextByHtml($html)
7878

7979
public static function getTitleTextByHtml($html)
8080
{
81-
$dom = new \DOMDocument();
82-
@$dom->loadHTML($html, LIBXML_NOERROR | LIBXML_NOWARNING);
83-
$title = $dom->getElementsByTagName('title')->item(0)->nodeValue;
81+
try {
82+
$dom = new \DOMDocument();
83+
@$dom->loadHTML($html, LIBXML_NOERROR | LIBXML_NOWARNING);
84+
$title = $dom->getElementsByTagName('title')->item(0)->nodeValue;
85+
} catch (\Throwable $th) {
86+
$title = '';
87+
}
8488
return trim($title);
8589
}
8690

0 commit comments

Comments
 (0)