How to retrieve content from a remote HTML page

I want to get the remote html content that is on "li", with the class spatial name and em child elements using the div.

My deleted content is similar to this

My name 1

20

My name 2

23

My name 3

40

After receiving their data, it should be like that.

[My Name 1.20]

[My name is 2.23]

[My Name 3.40]

Thanks.

Sorry for bad english

Note. You have more content than on the remote page.

+6
source share
1 answer

Use CURL to read the remote URL to retrieve the HTML.

$url = "http://www.example.com"; $curl = curl_init($url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); $output = curl_exec($curl); curl_close($curl) 

Then use the PHP DOM object model to parse the HTML.

For example, to get all the <h1> tags from the source,

 $DOM = new DOMDocument; $DOM->loadHTML( $output); //get all H1 $items = $DOM->getElementsByTagName('h1'); //display all H1 text for ($i = 0; $i < $items->length; $i++) echo $items->item($i)->nodeValue . "<br/>"; 
+24
source

Source: https://habr.com/ru/post/921734/


All Articles