P
P
password222019-07-06 18:49:44
PHP
password22, 2019-07-06 18:49:44

Searching for a specific fragment in html files, how to do it massively?

Hello. I don’t know how to do this, so I indicated both php and the parser.
There are, let's say, 20,000 website pages on html. I need to pull the content of a div out of them with some class. How can I do it? Maybe some kind of program?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene, 2019-07-06
@password22

suppose that all files are in dir1, and new ones will be created in "file name/class name.html"

$class = 'text_text'; //какой класс ищем...

foreach (glob("dir1/*.html") as $filename) {
  $html = file_get_contents($filename);
  preg_match('<div class="'.$class.'">(.*)</div>', $html, $result);
  file_put_contents($filename.'/'.$class.'.html', $result[0]);
}

I have trouble with regular expressions) but in theory the code should work)) well, xs, how long will it take .... more experienced guys can correct something ...

A
Arthurka, 2019-07-06
@Arthurka

1. Do a loop for 20000.
2. Do a folder opening.
3. We check each line for the presence of the desired class.
4. If found - create a folder and enter data

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question