HTML manipulation with PHP/JS

Asked

Viewed 620 times

0

How to get content from a page with Javascript?

With the content obtained through Javascript (or PHP), how to manipulate it in both languages, in order to read the values, as we do in Javascript when we are manipulating the DOM elements.

What I want to do?

Capturing values from a sequence of 50 URLS (then 50 pages), which follow the same pattern of formatting, as the site that I want to accomplish such a feat does not provide an API to return the data to me in an easily manipulated format (such as returning data in XML or JSON), I think the only way would be to get the data with Curl or file_get_contents, and manipulating all this HTML text, the main issue is how to manipulate an HTML formatted text with PHP.

I cited how to manipulate with Javascript a text (which could have been obtained with iframe for example) only in order to take advantage of the scope of the question and remedy this other doubt.

  • 1

    I do not understand the reason to manipulate HTML content with PHP, since with JS it works cute, and without being too costly to the server, PHP has its greatest back-end utility, data recording, recovery of the same and so on. Unless it is a dynamic search in which a refresh on the page is not very costly to the server. You can give examples of use?

  • 1

    Can you explain the question further?

  • 1

    Manipulate the DOM with JS is one thing, and using XML is another too, but what is the need to handle using both ? It’s really necessary ?

  • I would like to manipulate an HTML to simply get a value that is on the page, unfortunately there is no API on the site where this value would be returned to me in JSON or XML format, so I do it in the style it gives, which would get the HTML from the page and manipulate itTo get the value I’m looking for. I could say that I have a ratio of 50 URLS, and these URLS lead to different products, I just want to capture the value of the products (which are visible on the page and obey a formatting pattern) and record in the database the URLS and their respective values.

  • It is nothing that involves the client, just not to do manually would like this process to be automatic, go to the product of the URL, capture the value, and write to the database, so you are privileging PHP.

1 answer

2

A simple and functional example of how to get the html of a page as well as retrieve a certain value from within this html can be found here: http://simplehtmldom.sourceforge.net

But I make my own the words of our comrade Marcelo.

Only perform this type of action in the back end if it is really necessary, ie in last resort.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.