I describe the task completely, so that the context is clear: Get a specific page through curl. For example, this is a product page. The man clicked on the price. Determine the item. If it contains an id, stop. If not, look for the nearest parent with id. Then we look for the nearest parent with class. The element itself is already known to us.

I myself am not interested in finding items. It is interesting whether it is possible by the automaton to compose a regular expression that will find and get a number, having a sequence of parent id, nested class name and nested element. If possible, tell me how to do it correctly.

Closed due to the fact that off-topic participants rjhdby , HamSter , Denis , aleksandr barakin , Grundy 29 Oct '16 at 11:08 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - rjhdby, HamSter, Denis, aleksandr barakin, Grundy
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • What kind of digit should find reg.expression on the basis of at least a number, but it is even likely that you don’t even have a string from id, class and element, but it’s not clear what? - Visman
  • Corrected the number figure. Excuse me. - Andrew Godin

1 answer 1

I understood how to proceed. No need to try to invent one regular expression. We need a cascade of regular expressions that will eventually lead to our element. Generating such a cascade is not at all difficult. It will be even easier to use PHP Simple HTML DOM Parser In a maximum of 3 steps you can reach any element.

  • Nice to see such answers. Honestly. - ReinRaus
  • Thank. I was also told about the version with xpath. Now it has stopped in this direction, but I will continue soon. - Andrew Godin