PHP - 简单的 HTML Dom 问题
PHP - Simple HTML Dom Questions
基本上我试图抓取 IMDB 来检查有多少季,我怎么能基本上做这样的事情而是让它只输出总共有多少而不是只输出 1 2 3 4 5 如果节目有 5 个季节,如果它有 10 个季节,它会输出 1 2 3 4 5 6 7 8 9 10 但如果系列有 9 个季节,我只希望它输出 9。我该怎么做?
这是我当前的代码:
$seasons = $_GET['seasons'];
$url = 'http://www.imdb.com/title/'.$seasons.'/episodes';
$imdb_content = file_get_contents($url);
$html = str_get_html($imdb_content);
//Grabbed Content
$p = $html->find('select[id="bySeason"] option',0)->plaintext;
$p1 = $html->find('select[id="bySeason"] option',1)->plaintext;
$p2 = $html->find('select[id="bySeason"] option',2)->plaintext;
$p3 = $html->find('select[id="bySeason"] option',3)->plaintext;
$p4 = $html->find('select[id="bySeason"] option',4)->plaintext;
$p5 = $html->find('select[id="bySeason"] option',5)->plaintext;
$p6 = $html->find('select[id="bySeason"] option',6)->plaintext;
$p7 = $html->find('select[id="bySeason"] option',7)->plaintext;
$p = $html->find('select[id="bySeason"] option',8)->plaintext;
$p = $html->find('select[id="bySeason"] option',9)->plaintext;
$p = $html->find('select[id="bySeason"] option',10)->plaintext;
$p = $html->find('select[id="bySeason"] option',11)->plaintext;
$p = $html->find('select[id="bySeason"] option',12)->plaintext;
$p = $html->find('select[id="bySeason"] option',13)->plaintext;
$p = $html->find('select[id="bySeason"] option',14)->plaintext;
$p = $html->find('select[id="bySeason"] option',15)->plaintext;
$p = $html->find('select[id="bySeason"] option',16)->plaintext;
$p = $html->find('select[id="bySeason"] option',17)->plaintext;
$p = $html->find('select[id="bySeason"] option',18)->plaintext;
$p = $html->find('select[id="bySeason"] option',19)->plaintext;
$p = $html->find('select[id="bySeason"] option',20)->plaintext;
$p = $html->find('select[id="bySeason"] option',21)->plaintext;
$p = $html->find('select[id="bySeason"] option',22)->plaintext;
$p = $html->find('select[id="bySeason"] option',23)->plaintext;
$p = $html->find('select[id="bySeason"] option',24)->plaintext;
$p = $html->find('select[id="bySeason"] option',25)->plaintext;
$p = $html->find('select[id="bySeason"] option',26)->plaintext;
$p = $html->find('select[id="bySeason"] option',27)->plaintext;
$p = $html->find('select[id="bySeason"] option',28)->plaintext;
$p = $html->find('select[id="bySeason"] option',29)->plaintext;
$p = $html->find('select[id="bySeason"] option',30)->plaintext;
//Content
$content = "";
$content.= $p;
$content.= $p1;
$content.= $p2;
$content.= $p3;
echo $content;
不确定我是否理解正确。这是 simple_html_dom.
的《权力的游戏》季数
<?php
include("simple_html_dom.php");
$url = 'http://www.imdb.com/title/tt0944947/episodes';
$imdb_content = file_get_contents($url);
$html = str_get_html($imdb_content);
foreach($html->find('select[id="bySeason"] option') as $season){
$last_season = $season->plaintext;
}
echo $last_season;
Output is: 7
参考文献:
真的很简单:
echo count($html->find('#bySeason option'));
基本上我试图抓取 IMDB 来检查有多少季,我怎么能基本上做这样的事情而是让它只输出总共有多少而不是只输出 1 2 3 4 5 如果节目有 5 个季节,如果它有 10 个季节,它会输出 1 2 3 4 5 6 7 8 9 10 但如果系列有 9 个季节,我只希望它输出 9。我该怎么做?
这是我当前的代码:
$seasons = $_GET['seasons'];
$url = 'http://www.imdb.com/title/'.$seasons.'/episodes';
$imdb_content = file_get_contents($url);
$html = str_get_html($imdb_content);
//Grabbed Content
$p = $html->find('select[id="bySeason"] option',0)->plaintext;
$p1 = $html->find('select[id="bySeason"] option',1)->plaintext;
$p2 = $html->find('select[id="bySeason"] option',2)->plaintext;
$p3 = $html->find('select[id="bySeason"] option',3)->plaintext;
$p4 = $html->find('select[id="bySeason"] option',4)->plaintext;
$p5 = $html->find('select[id="bySeason"] option',5)->plaintext;
$p6 = $html->find('select[id="bySeason"] option',6)->plaintext;
$p7 = $html->find('select[id="bySeason"] option',7)->plaintext;
$p = $html->find('select[id="bySeason"] option',8)->plaintext;
$p = $html->find('select[id="bySeason"] option',9)->plaintext;
$p = $html->find('select[id="bySeason"] option',10)->plaintext;
$p = $html->find('select[id="bySeason"] option',11)->plaintext;
$p = $html->find('select[id="bySeason"] option',12)->plaintext;
$p = $html->find('select[id="bySeason"] option',13)->plaintext;
$p = $html->find('select[id="bySeason"] option',14)->plaintext;
$p = $html->find('select[id="bySeason"] option',15)->plaintext;
$p = $html->find('select[id="bySeason"] option',16)->plaintext;
$p = $html->find('select[id="bySeason"] option',17)->plaintext;
$p = $html->find('select[id="bySeason"] option',18)->plaintext;
$p = $html->find('select[id="bySeason"] option',19)->plaintext;
$p = $html->find('select[id="bySeason"] option',20)->plaintext;
$p = $html->find('select[id="bySeason"] option',21)->plaintext;
$p = $html->find('select[id="bySeason"] option',22)->plaintext;
$p = $html->find('select[id="bySeason"] option',23)->plaintext;
$p = $html->find('select[id="bySeason"] option',24)->plaintext;
$p = $html->find('select[id="bySeason"] option',25)->plaintext;
$p = $html->find('select[id="bySeason"] option',26)->plaintext;
$p = $html->find('select[id="bySeason"] option',27)->plaintext;
$p = $html->find('select[id="bySeason"] option',28)->plaintext;
$p = $html->find('select[id="bySeason"] option',29)->plaintext;
$p = $html->find('select[id="bySeason"] option',30)->plaintext;
//Content
$content = "";
$content.= $p;
$content.= $p1;
$content.= $p2;
$content.= $p3;
echo $content;
不确定我是否理解正确。这是 simple_html_dom.
的《权力的游戏》季数<?php
include("simple_html_dom.php");
$url = 'http://www.imdb.com/title/tt0944947/episodes';
$imdb_content = file_get_contents($url);
$html = str_get_html($imdb_content);
foreach($html->find('select[id="bySeason"] option') as $season){
$last_season = $season->plaintext;
}
echo $last_season;
Output is: 7
参考文献:
真的很简单:
echo count($html->find('#bySeason option'));