0

this is the format of description on google result.i want get description text.

Note: The description text may contain char <.

<div class="BNeawe s3v9rd AP7Wnd">
    <div>
        <div>
            <div class="BNeawe s3v9rd AP7Wnd">
                <span dir="rtl"> discription text. i want this. </span>
            </div>
        </div>
    </div>
</div>

how can i get the the most internal div with class BNeawe s3v9rd AP7Wnd?

i try this regular expression but it not work correctly.

preg_match_all(
    '/<div class="BNeawe s3v9rd AP7Wnd">'.
        '(<span dir="rtl">)?'.
            '( ( [^<]* (<(?!\/|span|div))? )* )'.           // I guess the problem is in this line.
        '(<\/span>)?'.
    '<\/div>/',
    $gp,
    $desc
  );
user3783243
  • 5,368
  • 5
  • 22
  • 41
ddd
  • 13
  • 8
  • Don't use regex for HTML parsing, use a parser. `[I WANT THIS TEXT]` means you want the last sentence or please define a pattern for that bit. A regex might be needed there but should not be used for HTML. – user3783243 Aug 17 '21 at 12:20
  • Yeah, the regex does not work at all as you don't consume anything between open/close `div`. Use the HTML parser. – Wiktor Stribiżew Aug 17 '21 at 12:48

0 Answers0