之前在博客中我推荐大家使用queryList来解析dom,但是在我长期的爬虫工作中来看它的bug很多。于是推荐这个symfony官方组件。
安装包:
composer require symfony/dom-crawler
安装css选择器
composer require symfony/css-selector
创建爬虫解析例子:
$response = file_get_contents('https://xxx.net/xxx/2485.html');
$crawler = new Crawler($response);
$href = $crawler->filter('.container .sub-left .sub-left-content .title p a')->eq(1)->attr('href');
echo $href; <?php //对比$this和self /* * $this更倾向于对象本身 * */ class Par{ public  ...
原理:使用curl_init()创建多个请求实例,再使用curl_multi_init()批量执行创建的多个请求实例。文件1:curl.php<?php $threads=500;//并发请求次数 $url='http://blog.cn/index.php?';...
(1).学习的目标:学会创建父子进程,并且能够区分当前进程是父还是子;了解父进程执行过程,子进程执行过程;能够用多进程执行任务(2).相关函数学习: (2.1)pcntl_fork()执行时: &nbs...
<?php //php7+ define('CONFIG', [ 'MYSQL' => '127.0.0.1',  ...
当我想在一个进程中监听kill 和 kill -9命令报了这个错误。//监听kill pcntl_signal(SIGTERM, function () { posix_kill(0, SIGTERM); });...
将jsonp转为PHP数组和对象。/** * jsonp转数组|Jsonp转json * @param string $jsonp jsonp字符串 * @param bool $as...