Created
October 5, 2012 22:35
-
-
Save b0n/3842865 to your computer and use it in GitHub Desktop.
簡単!たった10行のコードでHTML取得&解析をするPHPスクリプト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$url = 'http://www.yahoo.co.jp'; | |
$user_agent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)"; | |
$opts = array( | |
'http' => array( | |
'method' => 'GET', | |
'user_agent' => $user_agent, | |
)); | |
$context = stream_context_create($opts); | |
$result = file_get_contents($url, false, $context); | |
$xml = simplexml_import_dom(DOMDocument::loadHTML($result)); | |
$items = $xml->xpath("//*[@id='topicsfb']//li"); | |
//print_r($items); | |
foreach($items as $item) { | |
echo $item->a, PHP_EOL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment