- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
href ); echo ""; } -6ren">
<?php
// Report all PHP errors (see changelog)
error_reporting(E_ALL);
include('inc/simple_html_dom.php');
//base url
$base = 'https://play.google.com/store/apps';
//home page HTML
$html_base = file_get_html( $base );
//get all category links
foreach($html_base->find('a') as $element) {
echo "<pre>";
print_r( $element->href );
echo "</pre>";
}
$html_base->clear();
unset($html_base);
?>
我有上面的代码,我正在尝试获取 Play 商店页面的某些元素,但它没有返回任何内容。是否有可能在服务器上禁用某些 PHP 函数来阻止它?
以上代码在其他网站上完美运行。
有什么解决方法吗?
最佳答案
正如我所说,您的示例对我来说工作正常......但请尝试使用 curl 代替:
//base url
$base = 'https://play.google.com/store/apps';
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_URL, $base);
curl_setopt($curl, CURLOPT_REFERER, $base);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$str = curl_exec($curl);
curl_close($curl);
// Create a DOM object
$html_base = new simple_html_dom();
// Load HTML from a string
$html_base->load($str);
//get all category links
foreach($html_base->find('a') as $element) {
echo "<pre>";
print_r( $element->href );
echo "</pre>";
}
$html_base->clear();
unset($html_base);
它按预期获得所有链接:
并确保您安装了 php_openssl
和 php_curl
...
关于php - 简单的 html dom file_get_html 不工作 - 有什么解决方法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18667441/
我有一个充满 MySQL 表中链接的数据库,我想解析每个链接并将输出移动到一个新文件。不幸的是,每当我在 while 循环内使用 include("getContent.php") 时,我都会收到错误
我创建了一个脚本,让您可以在文本字段中发布链接,然后将图片从 url 上传到 MYSQL。该脚本在 WAMP 服务器中运行正常,但是当我将脚本上传到服务器时,收到错误消息: PHP 警告:file_g
我正在使用简单的 html dom 来解析 itunes 预览页面 当我将 URL 放入代码 [download]url[/download] 时一切正常,但是当我有 2 个或更多 [download
我正在尝试从某些网站抓取数据。对于几个网站来说,一切似乎都很顺利,但对于一个网站来说,它似乎无法获取任何 HTML。这是我的代码: 我正在使用ajax来获取数据。当我在 js 中记录返回值时,它完全
我正在尝试从某些网站上抓取数据。对于几个网站,一切似乎都很好,但对于一个网站,它似乎无法获取任何 HTML。这是我的代码: 我正在使用 ajax 获取数据。当我在我的 js 中记录返回值时,它完全是
我在使用一个相当简单的抓取程序时遇到了一些问题。希望这些工作部分可以帮助感兴趣的人建立新闻聚合器。我喜欢获取特定的内容,所以我发现抓取内容并按关键字过滤可以帮助我避免关于与我生活无关的事情的头条新闻这
我已经阅读了很多关于这里的问题,我不确定我是否应该为此使用 file_get_contents 或 file_get_html。 我想做的就是使用 PHP 在我的网站上显示此页面中的两个表:http:
我们正在尝试从 PHP DOM 获取 url,但我们尝试获取的 webapge 具有功能(页面加载后更改价格),所以现在我们需要 PHP DOM 功能file_get_html 完成此远程页面的onl
我正在使用 PHP 尝试抓取一个页面,该页面似乎在父页面完成加载后的几毫秒内动态加载内容。 我正在使用 curl 来解析页面,并使用 simpleHtmlDom 从解析的 html 中抓取内容。 我在
我使用以下代码解析另一个站点的 HTML,但它显示 fatal error : $html=file_get_html('http://www.google.co.in'); Fatal error:
find('a') as $element) { echo ""; print_r( $element->href ); echo ""; }
我是一名优秀的程序员,十分优秀!