Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to parse html with xpath in php

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article Xiaobian introduces in detail for you "php how to use xpath to analyze html", the content is detailed, the steps are clear, and the details are handled properly. I hope that this article "php how to use xpath to parse html" can help you solve your doubts.

Example 1

$xml = simplexml_load_file ('https://forums.eveonline.com'); $names = $xml- > xpath ("html/body/p/p/form/p/p/p/p/p [*] / p/p/table//tr/td [@ class='topicViews']"); foreach ($names as $name) {echo $name. ";}

Example 2

$url = 'http://www.baidu.com';$ch = curl_init (); curl_setopt ($ch, CURLOPT_FILE, fopen (' php://stdout', 'w')); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt ($ch, CURLOPT_URL, $url); $html = curl_exec ($ch); curl_close ($ch); / / create document object model$dom = new DOMDocument (); / / load html into document object model@$dom- > loadHTML ($html); / / create domxpath instance$xPath = new DOMXPath ($dom) / / get all elements with a particular id and then loop through and print the href attribute$elements = $xPath- > query ('/ / * [@ id= "lg"] / img/@src'); foreach ($elements as $e) {echo ($e-> nodeValue) } after reading this, the article "how to parse html with php with xpath" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report