D
D
Davlik2016-11-14 09:41:14
PHP
Davlik, 2016-11-14 09:41:14

How to parse specific column from html table?

There is a table:
https://jsfiddle.net/zghmnt17/
Please push, how can I output to an array of a specific column?

Array(
[8:30-10:00] => "Языки программирования..."
[10:10-11:40] => "Мат логика"
...
)

Currently using Simple HTML DOM
error_reporting(E_ALL);
  ini_set('allow_url_fopen','1');
  include_once('simple_html_dom.php');
  $html = file_get_html('http://kpfu.ru/week_sheadule_print?p_group_name=09-533');
  foreach($html->find('table tr td') as $e){
    $arr[] = trim($e->innertext);
  }
  
  print_r($arr);

The array is displayed completely, each value is also in krakozyabra (diamonds with a question inside, but this is not the main problem).
Maybe someone did something similar?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene Volf, 2016-11-14
@Davlik

foreach($html->find('table tr td') as $e){
Your selector does not correspond to the task at hand, it should either look something like this:
or, like this:
where 3 is the index of the element in the set, relative to the parent (starts from zero, if my memory serves me right).
I can’t say exactly how to write correctly within the framework of php_simple_html_dom (I last used phpQuery and then DomCrawler (from Symfony)), but the main point is that you must find / use an analogue of the eq filter from JQuery.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question