前提・実現したいこと
特定のURLから<body>タグを取得しています。JavaScript内の要素を取得した際にJavaScript内にある日本語が数値として抽出されてしまい、困っています。
JavaScript内にある「httpから始まるURL」の箇所を抽出すると、出力結果の最後にある数字の羅列「http1236312425229871241412427URL」
のように「から始まる」が数値として抽出されてしまいます。
日本語のまま抽出したいのですが、どのようにすればよいのでしょうか?
該当のソースコード
<!DOCTYPE html> <html> <head> <title>研究</title> </head> <body> <?php $opts = array('http'=>array('header' => "User-Agent:MyAgent/1.0rn")); $context = stream_context_create($opts); $url ="https://www.ana.co.jp/inttour/booking/csm/search/ISAP1100/initcourseNo=5HEP5NY1M0&planTypeCode=++&planTypeBranchNo=++&deptYearMonth=201901&deptDay=22&deptEndYearMonth=&deptEndDay=&isSearchTransition=true&cabinClass=0&coopSiteCode=" ; $html = file_get_contents($url,false,$context); $dom = new DOMDocument; @$dom->loadHTML( mb_convert_encoding($html, 'HTML-ENTITIES', 'ASCII,JIS,UTF-8,eucJP-win,SJIS-win'), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD ); $xpath = new DOMXPath($dom); foreach ($xpath->query('//body') as $body_result){ $body_values[] = preg_replace("/[^ぁ-んァ-ンーa-zA-Z0-9一-龠0-9\-\r]+/u", '', $body_result->nodeValue); } echo "<pre>"; print_r($body_values); echo "</pre>";
出力結果
Array ( [0] => 当サイトをご利用になるためにはJavaScript対応のブラウザが必要ですまた設定でJavaScriptを有効にする必要がありますトップページお問い合わせvarroomTypeTBvarerrorvaractiveButtondaylangjafunctionusestricthttp1236312425229871241412427URL
html内のJavaScript
<script type="text/javascript"> $(function() { 'use strict'; // httpから始まるURL var fullShareUrl = location.protocol + '//' + location.host + '/inttour/booking/csm/search/ISAP1100/init?courseNo=5HEP5NY1M0&deptYearMonth=201901&deptDay=22&planTypeCode=&planTypeBranchNo=&deptEndYearMonth=&deptEndDay=&isSearchTransition=true&cabinClass=0'; // facebookのdata-uri属性 $('#facebook-area').attr('href', 'http://www.facebook.com/share.php' + '?u=' + encodeURIComponent(fullShareUrl)); // Twitterリンクをセット $('#twitter-link').attr('href', 'https://twitter.com/share?hashtags=' + encodeURIComponent('ANA,ANAツアー,ANA_海外ツアー,ANA_海外旅行,旅行,Travel') + '&text=' + encodeURIComponent(document.title) + '&url=' + encodeURIComponent(fullShareUrl)); // google+のdata-href属性 $('#google-plus-area').attr('data-href', fullShareUrl); // メール // mailto:?subject=[件名]&body=[本文]%0d%0a[URL] // 件名はtitle, 本文はdescription var description = $('meta[name="description"]').attr('content'); var mailHref = 'mailto:?subject=' + encodeURIComponent(document.title) + '&body='+ encodeURIComponent(description + '\r\n' + fullShareUrl); $('#mail-link').attr('href', mailHref); }); </script>
補足情報(FW/ツールのバージョンなど)
ubuntu18.04
Apache/2.4.29
PHP 7.2.5
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/07/15 13:09
2018/07/16 03:56