Dan*_*naq 5 php laravel windows-subsystem-for-linux symfony-panther
我想在 Laravel 应用程序中使用 symfony panther 包抓取一个网站。根据文档https://github.com/symfony/panther#a-polymorphic-feline我不能使用HttpBrowser或这些HttpClient类,因为它们不支持JS。
因此,我尝试使用 ChromClient,它使用本地 chrome 可执行文件和 panther 包附带的 chromedriver 二进制文件。
$client = Client::createChromeClient();
$crawler = $client->request('GET', 'http://example.com');
dd($crawler->html());
Run Code Online (Sandbox Code Playgroud)
不幸的是,我只收到 HTML 格式的空默认 chrome 页面:
<html><head></head><body></body></html>
Run Code Online (Sandbox Code Playgroud)
使用$client或$crawler-instance 执行其他操作的每种方法都会导致错误“没有可用的节点”。
此外,我尝试了文档中的基本示例https://github.com/symfony/panther#basic-usage --> 相同的结果。
我在 Windows 上的 WSL 下使用 ubuntu 18.04 服务器并安装了google-chrome-stabledeb 包。这似乎有效,因为安装后不再出现“找不到二进制文件”的错误。
我还尝试手动使用 Windows 主机系统的可执行文件,但这只会打开一个空的 CMD 窗口,关闭时总是重新打开。我必须通过任务管理器终止该进程。
这是因为 Ubuntu 服务器没有任何可用的 x-server 吗?
我可以做什么来接收 HTML?
$client = Client::createChromeClient();
$crawler = $client->request('GET', 'http://example.com');
/**
* Get all Html code of page
*/
$client->getCrawler()->html();
/**
* For example to filter field by ID = AuthenticationBlock and get text
*/
$loginUsername = $client->getCrawler()->filter('#AuthenticationBlock')->text();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4586 次 |
| 最近记录: |