前提・実現したいこと
phpQuerryを用いてウェブサイトの内容をスクレイピングしようとした。
環境構築はほぼこの記事のまま。
発生している問題・エラーメッセージ
localhost:8080", referrer: "http://localhost:8080/" 2019/10/27 04:29:39 [error] 20534#0: *15 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught Error: Class 'DOMDocument' not found in /var/www/html/src/phpQuery-onefile.php:255 Stack trace: #0 /var/www/html/src/phpQuery-onefile.php(324): DOMDocumentWrapper->documentCreate('utf-8') #1 /var/www/html/src/phpQuery-onefile.php(244): DOMDocumentWrapper->loadMarkupHTML('<!DOCTYPE HTML ...') #2 /var/www/html/src/phpQuery-onefile.php(191): DOMDocumentWrapper->loadMarkup('<!DOCTYPE HTML ...') #3 /var/www/html/src/phpQuery-onefile.php(177): DOMDocumentWrapper->load('<!DOCTYPE HTML ...', NULL, NULL) #4 /var/www/html/src/phpQuery-onefile.php(4857): DOMDocumentWrapper->__construct('<!DOCTYPE HTML ...', NULL, NULL) #5 /var/www/html/src/phpQuery-onefile.php(4631): phpQuery::createDocumentWrapper('<!DOCTYPE HTML ...', NULL) #6 /var/www/html/src/form.php(41): phpQuery::newDocument('<!DOCTYPE HTML ...') #7 {main} thrown in /var/www/html/src/phpQuery-onefile.php on line 255" while reading response header from upstream, client: 10.0.2.2, server: _, request: "POST /src/form.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "
該当のソースコード
PHP
1 $index = dirname($filePath) . '/Index.htm'; 2 $tableList = phpQuery::newDocument(file_get_contents($index))->find('table')->find('tr');
Index.htmの中身はごく普通のHTMLファイルです。
試したこと
php-xmlがなかったのでyum-install
sudo systemctl reload nginx
vagrant reload
補足情報(FW/ツールのバージョンなど)
PHPinfoのdomのぶぶんには
dom DOM/XML enabled DOM/XML API Version 20031129 libxml Version 2.9.1 HTML Support enabled XPath Support enabled XPointer Support enabled Schema Support enabled RelaxNG Support enabled
と出ているので、DOM/XMLは読めているはず。。
あなたの回答
tips
プレビュー