我想在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());
不幸的是,我只收到HTML格式的空默认chrome页面:
<html><head></head><body></body></html>
使用$client
或$crawler
示例执行其他操作的每种方法都会导致错误“no nodes available”。
此外,我尝试了文档www.example.com中的基本示例https://github.com/symfony/panther#basic-usage--〉,结果相同。
我在Windows上使用WSL下的ubuntu18.04服务器,并安装了google-chrome-stable
deb-package。这似乎是工作的,因为在安装后,错误“二进制文件找不到”不再发生。
我还尝试手动使用Windows主机系统的可执行文件,但这只会打开一个空的CMD窗口,关闭时总是重新打开。我必须通过TaskManager杀死该进程。
这是因为Ubuntu服务器没有任何可用的x-server吗?
如何接收HTML?
2条答案
按热度按时间64jmpszr1#
fgw7neuy2#
所以,我可能迟到了,但我遇到了同样的问题,一个非常简单的解决方案:只需打开一个带有响应内容的简单爬虫。
这一个与Panther DomCrawler不同,特别是在方法上,但它在评估HTML结构时更安全。