0

I'm having trouble retrieving the nodevalue of a specific li-tag with four class names. It is the class name "b-programm_ended" that uniquely identifies it.

<?php
    $dom = new DOMDocument;
    $dom->loadHTMLFile('https://tv.mail.ru/channel/1296/65/');
    $xpath = new DOMXPath($dom);
    $classname = 'b-programm js-schedule_item js-remind_prnt b-programm_ended';
    $results = $xpath->query('//*[@class="'.$classname.'"]');
    echo $now = $results->item(0)->nodeValue;
?>
Tasos K.
  • 7,979
  • 7
  • 39
  • 63
Ace
  • 223
  • 4
  • 14

3 Answers3

1

This is not your real issue.

Unfortunately, you aren't ever going to be able to find any elements with class b-programm_ended. I looked at the source of https://tv.mail.ru/channel/1296/65/ and could not find any b-programm_ended strings. However, I inspected the DOM with Chrome and did find some instances of b-programm_ended. This means that class attributes are being created with jQuery, so your server-side PHP parsing will not find those tags.

However, when I inspect the XHR requests from the same site, there is some JSON data being pulled from

https://tv.mail.ru/ext/admtv/?sch.favorite_event=1&sch.recommended_main=1&cfg.get=1&sch.main=1&sch.channel=1296

that contains the data you may be looking for, for instance:

schedule: [{stop: "2015-04-26 05:15:00", name: "Белохвостые гиганты "Тэкомати"", genre_id: "142",…},…]
    0: {stop: "2015-04-26 05:15:00", name: "Белохвостые гиганты "Тэкомати"", genre_id: "142",…}
    episode_num: "6"
    episode_title: "402-я серия"
    genre_id: "142"
    id: "36239842"
    name: "Белохвостые гиганты "Тэкомати""
    start: "2015-04-26 04:50:00"
    stop: "2015-04-26 05:15:00"
    year: "2013"
    ...

My suggestion for you is to use a JSON parser (json_decode in PHP) and conveniently pick out the information you are looking for from that data structure.

Drakes
  • 23,254
  • 3
  • 51
  • 94
0
<?php
$dom = new DOMDocument;
$dom->loadHTMLFile('https://tv.mail.ru/channel/1296/65/');
$xpath = new DOMXPath($dom);
$classname = 'b-programm_ended';
$results = $xpath->query('//*[@class="'.$classname.'"]');
echo $now = $results->item(0)->nodeValue;
?>
David Soussan
  • 2,698
  • 1
  • 16
  • 19
0

since the b-program can be a unique selector for the required element, try the follosing code

<?php
error_reporting(0);
$dom = new DOMDocument;
$dom->loadHTMLFile('https://tv.mail.ru/channel/1296/65/');
$xpath = new DOMXPath($dom);
$classname = 'b-programm';
$results = $xpath->query('//*[@class="'.$classname.'"]');
echo $now = $results->item(0)->nodeValue;
?>
Anas
  • 576
  • 5
  • 10