php - Extracting Link Text From Specific Links -


i'm trying figure out how can titles of movies page.

i have this, cannot work. don't know domdocument. gets links on page. however, need links listed movie titles.

$content =  file_get_contents("http://www.imdb.com/movies-in-theaters/");  $dom = new domdocument(); $dom->loadhtml($content); $urls = $dom->getelementsbytagname('a'); 

$dom = new domdocument(); @$dom->loadhtmlfile('http://www.imdb.com/movies-in-theaters/'); $urls = $dom->getelementsbytagname('a'); $titles = array();  foreach ($urls $url) {     if ('overview-top' === $url->parentnode->parentnode->getattribute('class'))         $titles[] = $url->nodevalue; }  print_r($titles); 

will output:

array (     [0] =>  star trek darkness (2013)     [1] =>  frances ha (2012)     [2] =>  stories tell (2012)     [3] =>  erased (2012)     [4] =>  english teacher (2013)     [5] =>  augustine (2012)     [6] =>  black rock (2012)     [7] =>  state 194 (2012)     [8] =>  iron man 3 (2013)     [9] =>  great gatsby (2013)     [10] =>  pain & gain (2013)     [11] =>  peeples (2013)     [12] =>  42 (2013)     [13] =>  oblivion (2013)     [14] =>  croods (2013)     [15] =>  big wedding (2013)     [16] =>  mud (2012)     [17] =>  oz great , powerful (2013) ) 

you can use xpath well, don't know enough way.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -