これが重複した質問である場合は申し訳ありません。
ブラウザがモバイルでない場合、ターゲット サイトからデスクトップ サイトにリダイレクトされます。サイトのモバイル バージョン (http://mobile.mysite.com) を解析したいと考えています。サーバーが無効になっているため、Curl を使用できません。可能な場合、モバイルのユーザーエージェントは何でしょうか??!!
4 に答える
2
User-Agent
リクエストのようにカスタム ヘッダーを送信する必要がある場合file_get_contents
、それに対する PHP の回答はストリーム コンテキストです。
$opts = array(
'http' => array(
'method' => "GET",
'header' => "Accept-language: en\r\n" .
"Cookie: foo=bar\r\n" .
"User-Agent: Foo Bar Baz\r\n"
)
);
$context = stream_context_create($opts);
file_get_contents($url, false, $context);
stream_context_create
およびを参照してくださいfile_get_contents
。
于 2012-07-12T09:29:19.977 に答える
0
このphpライブラリを見てみてください:
また、モバイルサイトを取得する場合は、ユーザーエージェントを特定のモバイルブラウザに設定します
$userAgent = "NokiaC5-00/061.005 (SymbianOS/9.3; U; Series60/3.2 Mozilla/5.0; Profile/MIDP-2.1 Configuration/CLDC-1.1) AppleWebKit/525 (KHTML, like Gecko) Version/3.0 Safari/525 3gpp-gba";
setUserAgent($userAgent);
于 2012-07-12T09:31:54.710 に答える
0
カールなしでphp内のユーザーエージェントを変更するには、次のことを試してください。
<?php
ini_set('user_agent', 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7');
$data = file_get_contents("http://www.mobile.example.com");
?>
PS:ここからiphone 4のユーザーエージェントを手に入れました!
于 2012-07-12T09:33:24.287 に答える
0
モバイル User-Agent 文字列を選択して使用します。それらはGoogle から簡単に見つけることができます。
これらを で使用する方法を示すサンプル コードを次に示しますfile_get_contents()
。
<?php
// The first one I found on Google
$uaStr = 'Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91)';
// Create a stream context
// http://www.php.net/manual/en/context.http.php
$context = stream_context_create(array(
'http'=>array(
'user_agent' => $uaStr
)
));
// The URL
$url = "http://www.example.com/";
// Make the request
$result = file_get_contents($url, FALSE, $context);
于 2012-07-12T09:31:14.653 に答える