LoginSignup
2
4

More than 5 years have passed since last update.

クロスドメインで他のページを取得する方法

Last updated at Posted at 2016-10-27

他のページのHTMLを取得する方法

> クロスドメインで他のページを取得する方法

Ajaxで取得したHTMLからタイトルを取得する方法

index.html

<!DOCTYPE html>
<html lang="ja">
    <head>
        <meta charset="utf-8">
        <title>Get A Other Page Title</title>
    </head>
    <body>
        <script src="js/jquery.js"></script>
        <script src="index.js"></script>
    </body>
</html>

index.js

$.ajax({
    url: 'http://localhost/test/',
    type: 'GET',
    success: function(data) {
        console.log(data);
    }
});

PHP

echo file_get_contents('https://www.google.co.jp');

取得したページ

<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="ja"><head><meta content="世界中のあらゆる情報を検索するためのツールを提供しています。さまざまな検索機能を活用して、お探しの情報を見つけてください。" name="description"><meta content="noodp" name="robots">
...
2
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4