惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
C
CERT Recently Published Vulnerability Notes
C
Cybersecurity and Infrastructure Security Agency CISA
P
Proofpoint News Feed
Security Latest
Security Latest
P
Privacy International News Feed
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
AI
AI
Cisco Talos Blog
Cisco Talos Blog
K
Kaspersky official blog
S
Secure Thoughts
PCI Perspectives
PCI Perspectives
Simon Willison's Weblog
Simon Willison's Weblog
D
DataBreaches.Net
GbyAI
GbyAI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
罗磊的独立博客
V
Visual Studio Blog
aimingoo的专栏
aimingoo的专栏
H
Hackread – Cybersecurity News, Data Breaches, AI and More
IT之家
IT之家
V
V2EX
Last Week in AI
Last Week in AI
有赞技术团队
有赞技术团队
月光博客
月光博客
酷 壳 – CoolShell
酷 壳 – CoolShell
T
Tenable Blog
T
Threat Research - Cisco Blogs
T
Troy Hunt's Blog
V2EX - 技术
V2EX - 技术
S
Security @ Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
Project Zero
Project Zero
The GitHub Blog
The GitHub Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
L
Lohrmann on Cybersecurity
F
Full Disclosure
H
Help Net Security
博客园 - Franky
Stack Overflow Blog
Stack Overflow Blog
N
Netflix TechBlog - Medium
Engineering at Meta
Engineering at Meta
A
Arctic Wolf
O
OpenAI News
S
Securelist

个人技术分享

GPT指令详细资料 – 个人技术分享 php操作cookie 转换数组形式,可取某一个值 – 个人技术分享 php操作cookie字符串,替换对应值 – 个人技术分享 php 操作cookie值 – 个人技术分享 js 引入vconsole – 个人技术分享 fastadmin appendfieldlist 用法 – 个人技术分享 PHP 转到 Go – 个人技术分享 解决移动设备上的所有浏览器顶部都有地址栏,导致高度问题 – 个人技术分享 Python框架 Flask和Django – 区别 – 个人技术分享 PHP To Go 转型手记 – 个人技术分享 真正的50行css代码实现响应式“瀑布流”布局 – 个人技术分享
PHP使用无头浏览器如何帮助数据提取和抓取 – 个人技术分享
hanhanjun888 · 2024-07-24 · via 个人技术分享

php使用webdriver做采集的好处
自动化:WebDriver 可以模拟用户与浏览器的交互操作,如点击、输入文本、提交表单等。这使得您可以自动化执行各种网页操作,而无需手动进行。
多浏览器支持:WebDriver 支持多种浏览器,包括 Chrome、Firefox、Safari 等。这意味着您可以在不同的浏览器上运行和测试您的采集脚本,以确保在不同环境下的兼容性。
动态内容处理:许多网站使用 JavaScript 和 AJAX 技术来加载和更新内容。通过 WebDriver,您可以等待页面加载完成并获取完整的渲染后的页面内容,包括动态生成的内容。
数据抽取:WebDriver 提供了丰富的方法和选择器来定位和提取页面中的元素。您可以使用这些功能来获取所需数据,并将其保存到文件或数据库中进行进一步处理。
高度可定制化:WebDriver 允许您编写灵活且高度可定制化的采集脚本。您可以根据需要设置各种选项和参数,以适应不同网站和场景。
跨平台支持:WebDriver 是一个跨平台的工具,可以在 Windows、Mac 和 Linux 等操作系统上运行。这使得它成为一个广泛适用的采集解决方案。
使用方法
使用 WebDriver,您可以等待页面加载完成并获取完整的渲染后的页面内容,包括动态生成的内容。这意味着您可以采集到前后端分离网站上通过 JavaScript 或 AJAX 加载的数据。接下来让我自己动手写一个试试看。
安装浏览器chrome
1. 下载 Chrome 浏览器的安装包:
wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
2. 安装 Chrome 浏览器:
sudo yum localinstall google-chrome-stable_current_x86_64.rpm
3. 验证 Chrome 是否成功安装:
google-chrome –version
4. 下载对应版本的 ChromeDriver,并解压到指定目录(例如 /usr/local/bin):
https://googlechromelabs.github.io/chrome-for-testing/ (各个版本的下载地址)
wget https://chromedriver.storage.googleapis.com/114.0.5735.90/chromedriver_linux64.zip
unzip chromedriver_linux64.zip -d /usr/local/bin/
5. 启动 ChromeDriver 服务:
LANGUAGE=ZH-CN.UTF-8 /usr/local/bin/chromedriver –port=9515
6.成功运行后,您应该会看到类似以下输出:
Starting ChromeDriver {version} on port 9515…
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
https://github.com/php-webdriver/php-webdriver
PHP+WebDriver使用教程

https://github.com/php-webdriver/php-webdriver

php代码执行

<?php
require_once('vendor/autoload.php');
use Facebook\WebDriver\Remote\DesiredCapabilities;

use Facebook\WebDriver\Remote\RemoteWebDriver;

use Facebook\WebDriver\Chrome\ChromeOptions;

$options = new ChromeOptions();

$options->addArguments(['--no-sandbox','--headless']);


$capabilities = DesiredCapabilities::chrome();

$capabilities->setCapability(ChromeOptions::CAPABILITY, $options);


$host = 'http://localhost:9555';

$driver = RemoteWebDriver::create($host, $capabilities);


// 访问百度网站

$driver->get('https://www.baidu.com');


// 获取页面源代码

$pageSource = $driver->getPageSource();


echo $pageSource;


// 关闭 WebDriver 会话

$driver->quit();