基本上我试图抓住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;
答案 0 :(得分:1)
不确定我是否理解正确。这是权力的游戏季节计数由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;
输出为:7
参考文献:
答案 1 :(得分:0)
这真的很简单:
echo count($html->find('#bySeason option'));