Goutte按类型获取脚本元素

时间:2018-03-25 22:11:15

标签: php dom screen-scraping goutte

我正在尝试使用Goutte来获取页面的内容,当浏览源代码时,我想要获取所有代码内容的脚本...

<script type='application/ld+json'>
"@context" : "http://schema.org",
"@type" : "LocalBusiness",
"name" : "Example",
</script>

我正在使用这样的东西,它适用于html元素,但不适用于脚本元素。

        $crawler->filter('.main_content')->each(function ($node) {

一旦我获得了内容,我想通过每个元素来爆炸它。

任何想法?

1 个答案:

答案 0 :(得分:0)

这对我来说很好:

$ crawler-> filterXpath('// script [@ type =“ application / ld + json”]');

docs:https://symfony.com/doc/current/components/dom_crawler.html