php如何用google play scraper获取元素的值?

时间:2018-05-08 11:09:55

标签: php html web-scraping

我正在使用google play scraper API调用html输入并获取其值 问题是有2个html输入具有相同的名称类,所以当我给出指向主题的路径时,我得到两个相同的结果, 当我给出安装html输入和更新的html输入的路径时,我正面临这种类的冲突,这是我用来调用的PHP代码 安装html输入:

$downloadsNode = $crawler->filter('.xyOfqd > .hAyfc > .htlgb > div > span ');
        if ($downloadsNode->count()) {
            $downloads = trim($downloadsNode->text());
        } else {
            $downloads = null;
        }

因此我获取更新的字段值因为它共享相同的类名。

这是Html代码源:

<div class="JHTxhe"><div class="xyOfqd"><div class="hAyfc"><div class="BgcNfc">Updated</div><span class="htlgb"><div><span class="htlgb">May 3, 2018</span></div></span></div><div class="hAyfc"><div class="BgcNfc">Size</div><span class="htlgb"><div><span class="htlgb">Varies with device</span></div></span></div><div class="hAyfc"><div class="BgcNfc">Installs</div><span class="htlgb"><div><span class="htlgb">1,000,000,000+</span></div></span></div><div class="hAyfc"><div class="BgcNfc">Current Version</div><span class="htlgb"><div><span class="htlgb">Varies with device</span></div></span></div><div class="hAyfc"><div class="BgcNfc">Requires Android</div><span class="htlgb"><div><span class="htlgb">Varies with device</span></div></span></div><div class="hAyfc"><div class="BgcNfc">Content Rating</div><span class="htlgb"><div><span class="htlgb"><div>Rated for 12+</div><div>Parental Guidance Recommended</div><div><a href="https://support.google.com/googleplay?p=appgame_ratings">Learn More</a></div></span></div></span></div><div class="hAyfc"><div class="BgcNfc">Interactive Elements</div><span class="htlgb"><div><span class="htlgb">Users Interact, Digital Purchases</span></div></span></div><c-wiz jsrenderer="HwUY7e" jsshadow="" jsdata="deferred-i23" data-p="%.@.[&quot;com.google.android.youtube&quot;,7]
]

你能不能帮助我

1 个答案:

答案 0 :(得分:0)

这就是我解决这个问题的方法,我添加了eq()函数,它解决了我的问题。

$downloadsNode = $crawler->filter('.xyOfqd > .hAyfc > .htlgb > div > span')->eq(2);