-3

外部サイトやタイトルページからメタを取得する方法

外部サイトからメタを取得する方法

<input type="text"value="http://"id="externalurl" />
4

1 に答える 1

2

個人的には、Javascript ではなく PHP を使用してこれを行います。JavaScript が本当に必要な場合は、PHP ページを AJAX にすることができます。この PHP ライブラリ " http://sourceforge.net/projects/simplehtmldom/ " を使用して開始し、次の行に沿って何かを実行します。

// Create DOM from URL or file
$url = 'http://www.example.com/';
$html = file_get_html($url);

// Find all meta tags
foreach($html->find('meta') as $element){
       $temp['name'] = $element->name;
       $temp['content'] = $element->content;
       $meta[] = $temp;
}
//Run checks on the array of meta tags or whatever you are trying to acheive

私は疲れ果てているのでこれをチェックしていませんが、この質問を見て、すぐにこのライブラリについて考えました! それが役に立てば幸い

テスト後の編集: 少しプレイした後、このコード:

<?php 
include('simple_html_dom.php');
// Create DOM from URL or file
$url = 'http://www.amazon.com/';
$html = file_get_html($url);

// Find all meta tags
foreach($html->find('meta') as $element){
        $temp['name'] = $element->name;
        $temp['content'] = $element->content;
        $temp['charset'] = $element->charset;
       $meta[] = $temp;
       $temp = "";
}
print_r($meta);
?>

出力:

Array
(
    [0] => Array
        (
            [name] => 
            [content] => on
            [charset] => 
        )

    [1] => Array
        (
            [name] => 
            [content] => text/html; charset=iso-8859-1
            [charset] => 
        )

    [2] => Array
        (
            [name] => description
            [content] => Online shopping from the earth&#39;s biggest selection of books, magazines, music, DVDs, videos, electronics, computers, software, apparel &amp; accessories, shoes, jewelry, tools &amp; hardware, housewares, furniture, sporting goods, beauty &amp; personal care, broadband &amp; dsl, gourmet food &amp; just about anything else.
            [charset] => 
        )

    [3] => Array
        (
            [name] => keywords
            [content] => Amazon, Amazon.com, Books, Online Shopping, Book Store, Magazine, Subscription, Music, CDs, DVDs, Videos, Electronics, Video Games, Computers, Cell Phones, Toys, Games, Apparel, Accessories, Shoes, Jewelry, Watches, Office Products, Sports &amp; Outdoors, Sporting Goods, Baby Products, Health, Personal Care, Beauty, Home, Garden, Bed &amp; Bath, Furniture, Tools, Hardware, Vacuums, Outdoor Living, Automotive Parts, Pet Supplies, Broadband, DSL
            [charset] => 
        )

    [4] => Array
        (
            [name] => google-site-verification
            [content] => 9vpzZueNucS8hPqoGpZ5r10Nr2_sLMRG3AnDtNlucc4
            [charset] => 
        )

)

これはほとんどすべてのようです!

于 2013-06-14T03:07:17.367 に答える