åãã¦ã®ã¹ã¯ã¬ã¤ãã³ã°
ç¾å¨ãå人ã¨Webãµã¼ãã¹ãä½ãè¨ç»ãããããã®ãµã¤ããä½ãããã«ã¹ã¯ã¬ã¤ãã³ã°ãå¿ è¦ã ã£ãã®ã§ã¡ãã£ã¨åå¼·ãã¦ã¿ã¾ããã
â»è¿½è¨
DOMããªã¼çæã¯æéããããã®ã§ãã¹ããæ·±ããªãå ´åã¯æ£è¦è¡¨ç¾ããªã¹ã¹ã¡ã§ã
ã¹ã¯ã¬ã¤ãã³ã°ã¨ã¯ï¼
ã¯ã¦ãªãã¼ã¯ã¼ãã«ããã¨ãã¦ã§ããµã¤ãã®ãã¼ã¿ãå¿
è¦ãªé¨åã ãæ½åºãã¦å©ç¨ãããã¨ãã ããã§ãã
ããã¦ã§ããµã¤ãã®ãã¼ã¿ãã¨ã£ã¦ãããã¨ãã«ãã®ãµã¤ãã®APIãæä¾ããã¦ããã°ãã®APIã使ç¨ããã°ããããã§ãããæä¾ããã¦ããªãå ´åã¯ãã¹ã¯ã¬ã¤ãã³ã°ãããå¿
è¦ãããããã§ãã
ä¾ãã°ãWikipediaã¯APIãæä¾ããã¦ããªãã®ã§å¿
è¦ãªãã¼ã¿ãã¨ã£ã¦ãããã¨ãã«ã¨ã£ã¦ããã¾ãããã¹ã¯ã¬ã¤ãã³ã°ããã°ã¨ã£ã¦ãããã¨ãã§ãã¾ãã
â»Wikipediaã¯idããã¾ãæå®ããªããµã¤ãæ§æãã¨ã£ã¦ããã®ã§ã¹ã¯ã¬ã¤ãã³ã°ã§ãã¼ã¿ãã¨ã£ã¦ã¯ãããã®ã§ãããããªãé¢åãããã§ãã
æ¹æ³
ããããæ¹æ³ããããã©ã¤ãã©ãªãå¤ãæä¾ããã¦ãã¾ããç§ã¯ãPHP Simple HTML DOM Parserãã使ãã¾ããã
å®è·µ
ã§ã¯å®éã«ãã£ã¦ã¿ã¾ãããã
ä¸è¨ã®ãµã¤ããåèã«ãã¾ããã
ITキヲスク | htmlSQLよりアツい!?jQueryみたいにセレクタでHTMLをparse(解析)する「PHP Simple HTML DOM Parser」
ã¾ãPHP Simple HTML DOM Parserãã¦ã³ãã¼ãã§ãããPHP Simple HTML DOM Parserã®Download latest version form Sourceforge.ãã®ãªã³ã¯å
ã«ããç·è²ã®ãã¿ã³ãæ¼ãã°ãã¦ã³ãã¼ãã§ãã¾ãã
使ç¨ããã®ã¯ããsimple_html_dom.phpãã ããªã®ã§ãããé©å½ãªå ´æã«ç½®ãã¦ä½¿ç¨ãã¾ãã
ä»åã¯ä¸æ¥ãã©ã´ã³ãºã®ææé£ãã¡ã®åçãã¨ã£ã¦ãããã¨æãã¾ãã
中日ドラゴンズ 公式サイト - 選手名鑑
ãµã¤ãã®æ§æã¯ä»¥ä¸ã®ãªã£ã¦ãã¾ãã

åçã¯idãpitcherã§ããdivã¿ã°ã®åè¦ç´ ã«ãããclassãplayer-photoã§ããdivã¿ã°å
ã®imgã¿ã°ã§ç®¡çããã¦ãã¾ãã
ãã®ã»ã¬ã¯ã¿ãfindãã¡ã³ã¯ã·ã§ã³ã®å¼æ°ã«è¨å
¥ãã¦ãããã¨ãã®æ
å ±ãã¨ã£ã¦ããã¾ãã
ä»åã¯src屿§ãç¸å¯¾ãã¹ã«ãªã£ã¦ããã®ã§src屿§ã ããå¼ã£ãæãã¦ãã¡ãã§çµ¶å¯¾ãã¹ã«ãªãããã«ç·¨éãã¦ãã¾ãã
ããsrc屿§ã ãã§ã¯ãªãimgã¿ã°å ¨ä½ãã¨ã£ã¦ãããå ´åã¯
$e->outertext;
ã¨ãã¦ãã ããã
詳ããã¯ãã¡ãã«è¼ã£ã¦ãã¾ããPHP Simple HTML DOM Parserマニュアル
ããã°ã©ã
<?php include('./simple_html_dom.php'); $url="http://dragons.jp/teamdata/players"; $html = file_get_contents($url); $htmlEnco = mb_convert_encoding($html, "UTF-8", "auto"); $htmlDom = str_get_html($htmlEnco); foreach($htmlDom->find('#pitcher .player-photo img') as $e){ echo "<img src=\""; echo "http://dragons.jp"; echo $e->src; echo "\" width=\"85\" height=\"94\">"; } ?>
æå¾ã«
ä»åã¯ãã¼ãã«ãªãµã¤ããåãä¸ãã¾ããããmixiãFacebookãªã©ã®ãã°ã¤ã³ããªãã¨ã¿ããªããµã¤ãã®ãã¼ã¿ãã¨ã£ã¦ãããå ´åã¯HTTP Clientã使ãã°ã¹ã¯ã¬ã¤ãã³ã°ã§ãã¾ããããã使ãã°ããªãã®æ°ã«ãªã£ã¦ããåã®ç»åãã¼ã¿ãFacebookãããããã¾è½ã¨ããã¨ãã§ããã®ã§ããç´ æ´ãããâ¦ï¼â
ã¾ããéä¿¡æ¹å¼ãSSL(https)æ¹å¼ã®å ´åã¯HTTP Classã使ç¨ããã°ã§ããã¿ããã§ããSSLã®å ´åã¯ã¾ã èªåããã£ããã¨ããªãã®ã§ã§ãããUPãããã¨æãã¾ãã
