linux中php-webdriver使用selenium

2025-09-12 00:22:25

1、selenium服务初始化

将上述selenium和ChromeDriver的两个文件放入一个文件夹中,运行cmd,输入如下命令初始化

linux中php-webdriver使用selenium

2、php-webdriver初始化

在使用php操作selenium前,需要先安装php-webdriver,一个由facebook维护的selenium插件,用于通过php来和selenium通信,composer方式安装这里不多介绍,这里仅介绍手动加载方式。

linux中php-webdriver使用selenium

3、然后在下方添加如下代码,初始化php-webdriver对象

linux中php-webdriver使用selenium

4、执行浏览器操作

打开淘宝登陆网页

linux中php-webdriver使用selenium

5、自动登陆

linux中php-webdriver使用selenium

6、获取页面内容

linux中php-webdriver使用selenium

7、内容分析

在通过php-webdriver获取到网页内容之后,可以直接用它的API来进行内容分析,但是因为习惯了用php-simple-html-dom-parser,所以这里还是用它来对抓取的内容进行分析。

安装php-simple-html-dom-parser,https://github.com/sunra/php-simple-html-dom-parser

手动引用插件

linux中php-webdriver使用selenium

8、将php-webdriver抓取的内容传递给php-simple-html-dom-parser

linux中php-webdriver使用selenium

9、php-simple-html-dom-parser支持通过str字符串获取网页内容,只需将php-webdriver获取的内容保存为字符串后传递给str_get_html函数

执行分析

linux中php-webdriver使用selenium

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢