##わからないこと
いつもお世話になっております。
この度、下記のサイトをスクレイピングしようとしているのですが、表示を送らせているためか、取得できておりません。
Phantomjsを用いて読み込ませようとしているのですが・・・
コードは下記のようになっております。
php
1public function handle() 2{ 3 // インスタンスの生成 4 $dom = new \DOMDocument(); 5 $areas = [ 6 '01', 7 ]; 8 foreach($areas as $area) { 9 $url = '"https://www.e-aidem.com/aps/list.htm?L=BMSList&PL=10&GMC=M02%3aM04%3aM12%3aM19%3aM20%3aM21&AC='.$area.'&ECD='.$area.'&SA=BCD%2cval88%2c_OPF2%2c_OPF%2cRUCD&NOI=50&P=1&SCD_=GG"'; 10 // 整形したxmlの取得 11 $xml = $this->phantomjsHtml($url); 12 dd($xml); 13} 14public function phantomjsHtml($url) { 15 // インスタンスの生成 16 $tidy = new \Tidy; 17 $arr = []; 18 // 文字列にてhtmを出力 19 exec('C:\X_DRIVE\asp\home\laravel\vendor\bin\phantomjs.exe C:\X_DRIVE\asp\home\laravel\public\js\crawler.js '.$url, $arr); 20 if(!$arr){ 21 \statusFailure(); 22 } 23 // 文字列結合 24 $html = ''; 25 foreach($arr as $parts){ 26 $html .= $parts; 27 } 28 // エラー文字の削除 29 $fileContent = str_replace('&', '&', $html); 30 $config = array( 31 // 'drop-empty-elements' => false, // 空の要素を削除しない 32 // 'hide-comments' => true, // コメントを削除 33 'output-xhtml' => true, // xhtml に変換 34 ); 35 36 37 $tidy->parseString($fileContent, $config, 'utf8'); 38 $tidy->cleanRepair(); 39 40 $xml = simplexml_load_string($tidy); 41 return $xml; 42 } 43}
javascript
1var page = require('webpage').create(); 2var system = require('system'); 3var args = system.args; 4 5var url = args[1]; 6if (url == undefined) { 7 phantom.exit(); 8} 9 10page.open(url, function(status) { 11 if (status === 'success') { 12 page.switchToFrame(0); 13 var body = page.evaluate(function() { 14 return '<html>' + document.getElementsByTagName('html')[0].innerHTML + '</html>'; 15 }); 16 console.log(body); 17 } 18 phantom.exit(); 19}); 20
ご助力いただけますと幸いです。
何卒よろしくお願い申し上げます。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。