PHP collection plug-in QueryList practical teaching (1)

安安杰尼
Release: 2020-04-29 09:59:11
Original
197789 people have browsed it

1: Demand background

As a developer, you will more or less encounter the need for collection in daily development, and you need to collect data, articles, etc. from a certain website. etc. At the same time, it is also necessary to analyze and classify the collected content. In the process of parsing and classifying, most PHPers use regular methods to analyze the crawled data, which increases the difficulty and does not improve the efficiency. Using QueryList can solve the problem of results very easily.

2: What is QueryList?

QueryList is an open source project based on phpQuery, which allows PHPer to perform a JQuery-like DOM operation on the content when collecting information. It is very simple and convenient, and fits the usual development habits.

3: Download and install

(1) Environmental requirements, there are two installation methods, you can select any of the following.

PHP >= 5.3
Copy after login

(2) Installation method - Use composer to install

composer require jaeger/querylist:V3.2.1
Copy after login

or add the following configuration to the composer.json file of the project, and then composer update

"require" : { "jaeger/querylist": "^3.2" }
Copy after login

After the installation is completed, In the project, directly introduce the vendor/autoload.php file and start using it directly

(3) Test

$html = <<  其它的一些文本 
STR; $rules = array( //采集id为one这个元素里面的纯文本内容 'text' => array('#one','text'), //采集class为two下面的超链接的链接 'link' => array('.two>a','href'), //采集class为two下面的第二张图片的链接 'img' => array('.two>img:eq(1)','src'), //采集span标签中的HTML内容 'other' => array('span','html') ); $data = QueryList::Query($html, $rules)->data; var_dump($data);
Copy after login

(4) Installation method-manual installation

Go to Github Download the code https://github.com/jae-jae/QueryL, get the two files QueryList.php and phpQuery.php and put them into the project

(5) Test

array('.unit h1 a','href'))); $data = $hj->getData(function($x){ return $x['url']; }); print_r($data);
Copy after login

Summary, downloading and installing this plug-in is very simple. In the next issue, I will introduce simple collection of article content, which is suitable for beginners to learn. Everyone is welcome to pay attention and receive new course reminders in time.

The above is the detailed content of PHP collection plug-in QueryList practical teaching (1). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!