如何从 itemprop 等于的外部页面获取内容..

How to get content from external page where itemprop equals...?

本文关键字:获取 外部 itemprop      更新时间:2023-09-26

我想从我在谷歌播放上的应用页面获取内容到我的网站。现在,我获得了 .content 类中包含的所有内容。但我只想获得安装数量。这个div 看起来像这样:

<div class="content" itemprop="numDownloads">  </div>

有人知道如何从.content类中获取itemprop="numDownloads"吗?

这是我现在的代码:

刀片.php

<?php echo file_get_contents($_GET['url']); ?>

脚本

<script>
  $(function(){
    var contentURI= 'https://play.google.com/store/apps/someapp .content';
    $('#response').load('grab.php?url='+ contentURI);
  });
</script>

您也可以在 PHP 或 JavaScript 中使用正则表达式。现在我已经实现了PHP版本,但是使用这种模式,它可以很容易地在javascript中实现:

$siteContent = ''
    . '<div class="content" itemprop="7">  </div>'
    . '<div class="content" itemprop="5768">  </div>'
    . '<div class="content" itemprop="69">  </div>';
$matches =array();
preg_match_all('/itemprop's*='s*[''"]([^''"]+)[''"]/im', $siteContent, $matches);
var_dump($matches[1]);

输出为:

array
  0 => string '7' (length=1)
  1 => string '5768' (length=4)
  2 => string '69' (length=2)