Ubuntu20.0.4 使用php-webdriver 实现爬虫
2021/9/10 7:04:00
本文主要是介绍Ubuntu20.0.4 使用php-webdriver 实现爬虫,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
参考
- https://blog.csdn.net/xc_zhou/article/details/82427060
- https://www.cnblogs.com/php12-cn/p/12609647.html
- https://blog.csdn.net/xingtianyao/article/details/88695125 设置ubuntu桌面开关
- https://blog.csdn.net/post_mans/article/details/80966589 设置ubuntu分辨率(因为截图会截不全)
步骤
- 安装谷歌浏览器
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb dpkg -i google-chrome-stable_current_amd64.deb
- 根据 谷歌浏览器版本下载对应的 chromedriver
wget https://npm.taobao.org/mirrors/chromedriver/xxxxx
- 安装桌面(不安装浏览器会乱码)
# 安装桌面 sudo apt install lightdm -y # 关闭:在图形界面下 终端输入 sudo service lightdm stop # 开启:在命令行输入: sudo service lightdm start
- 启动并监听4444 端口
sudo chmod 777 chromedriver ./chromedriver --port=4444
- 代码配置参数,沙盒模式
# 设置分辨率 $size = new WebDriverDimension(1280, 900); $driver->manage()->window()->setSize($size); $serverUrl = 'http://localhost:4444'; $capabilities = DesiredCapabilities::chrome(); $options = new ChromeOptions(); // 浏览器参数配置 // windows 下只需要--no-sandbox,linux需要'--headless','--no-sandbox' $options->addArguments(['--headless','--no-sandbox']); $capabilities->setCapability(ChromeOptions::CAPABILITY, $options); $driver = RemoteWebDriver::create($serverUrl, $capabilities, 36000000, 36000000);
这篇关于Ubuntu20.0.4 使用php-webdriver 实现爬虫的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-09-28怎么把PHP程序打包?-icode9专业技术文章分享
- 2024-09-28怎么用Phar打包PHP程序?-icode9专业技术文章分享
- 2024-09-13手动在github上下载的mfpt包,怎么放到thinkphp5.0框架并正常使用-icode9专业技术文章分享
- 2024-09-05python的<class 'bytearray'>相当于php的哪个数据类型-icode9专业技术文章分享
- 2024-09-05php 导出银行卡号避免科学技术法的方法-icode9专业技术文章分享
- 2024-08-30什么样的php代码质量差被称为垃圾代码-icode9专业技术文章分享
- 2024-08-30用 PHP 调用拼多多的接口以获取订单状态消息的步骤方法和代码示例-icode9专业技术文章分享
- 2024-08-27phpunit单元测试框架的入门和使用方法介绍-icode9专业技术文章分享
- 2024-08-24PHP 中date("w") 周一是多少-icode9专业技术文章分享
- 2024-08-14thinkphp8.0获取域名或主机名方法-icode9专业技术文章分享