Z
Z
Zimaell2019-09-12 18:59:58
PHP
Zimaell, 2019-09-12 18:59:58

How to pull out the right elements?

The question is how to pull out the elements correctly, for example, I need to pull the price from the page

/*
часть исходного кода 
<span id="priceblock_dealprice" class="a-size-medium a-color-price priceBlockDealPriceString">13,49&nbsp;€</span>
*/
... curl_multi_init()...
foreach($channels as $url=>$ch){
  $content=trim(curl_multi_getcontent($ch));
  if(preg_match("/\<span id\=\"priceblock\_dealprice\"/i",$content)){
     $a=explode('<span id="priceblock_dealprice"',$content);
     $a2=explode('</span>',$a[1]);
     $a3=explode('>',$a2[0]);
     $price=trim(strip_tags($a3[1]));
     $a=explode(' ',$price);
     $cost=$a[0];
     echo $cost;
     }

I will say right away, I understand that it looks very scary, even though it works ...
Tell me how to properly pull out these elements, in what way, whether everything needs to be placed in $content or somehow it can be done differently, just when there are several hundred at once in a multi Then the operative eats well, in general, what do you advise?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Enj0y, 2019-09-12
@Zimaell

You are not doing it right, everything has already been invented before you, and besides, PHP has 2, if I am not mistaken, native HTML parsers, XPath for example.
I am using https://sourceforge.net/projects/simplehtmldom/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question