之前在博客中我推荐大家使用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 //高先生简单验证码. //随机数 //为什么循环0-15的数字 //因为要实现最简单的字母和数字混搭 //16进制0-9 a-f //dechex 十进制转换为16进制 //创建一个四位的验证码. //$nmsg.  ...
先看看下面的代码:<?php session_start(); $_SESSION['username']='lucy'; ?>当我们请求访问上面的脚本,默认会在我们的客户端生成一个名为PHPSESSID的cookie,我这里的值是PHPSESSID=...
原理:使用curl_init()创建多个请求实例,再使用curl_multi_init()批量执行创建的多个请求实例。文件1:curl.php<?php $threads=500;//并发请求次数 $url='http://blog.cn/index.php?';...
(1).创建数据库test ,创建表shop(字段id,total),商品id是1,商品总数10 (2).PHP模拟购买,商品数量大于0才能购买<?php //连接数据库 $con=mysqli_connect("192.168.2.18...
(1).config.php 配置文件<?php /** * RabbitMQ_Config */ $config = [ 'host' => ...
【一】.迭代器迭代是指反复执行一个过程,每执行一次叫做一次迭代。比如下面的代码就叫做迭代:1. <?php 2. $data = ['1', '2', &...