Answer the question
In order to leave comments, you need to log in
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
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]);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question