Phpquery collection webpage implementation code example



There may be a problem in normal development. Collect web pages, thief programs and so on. All kinds of fancy show regular words, although can reflect the geek, but I think things are not elegant enough. The collected web pages are also DOM, and jQuery obtains nodes gracefully. Fortunately, this class library helps us solve this problem, that is phpquery

Why use phpquery

Phpquery is a new domdocument based on PHP5. Domdocument is used to process HTML / XML. It provides powerful XPath selector and many other HTML / XML operation functions, which makes it very convenient to process HTML / XML.

Especially for novices, when they see a pile of “unknown” character comments together, they feel like their heads are going to explode. If the object to be separated has no obvious features, regular writing is even more troublesome.

The learning cost is low. JQuery is the standard configuration of PHP programmers. If you understand jQuery, you can connect seamlessly. The learning cost is almost zero. Selector, node, node information, over

Download address (you need to go over the wall, or Baidu phpquery on your own)


Now that we have started, let’s do an experiment. For example, we need to get all the tag names of SF And review the elements to get some tag attributes. < a data original title = “load balancing” > Load Balancing</a>


  require(" phpQuery.php "); // import phpquery Library
  $html   = phpQuery::newDocumentFile("");
  $hreflist = PQ (". Tag"); // get all objects with label a $(". Tag")

  foreach ($hrefList as $href) {
    echo $href->getAttribute("data-original-title"),"<br>";



0. Web page collection is really special. It has no brain violence and successfully bypasses the disgusting routine

1. Refer to jQuery

2. Experience DOM’s thoughts

3. This kind of library is not a panacea, it is more suitable for web page collection

The above is the whole content of this article, I hope to help you learn, and I hope you can support developer more.

Recommended Today

Third party calls wechat payment interface

Step one: preparation 1. Wechat payment interface can only be called if the developer qualification has been authenticated on wechat open platform, so the first thing is to authenticate. It’s very simple, but wechat will charge 300 yuan for audit 2. Set payment directory Login wechat payment merchant platform( pay.weixin.qq . com) — > Product […]