Php 使用简单html dom从网页中提取值
我在网上搜索并找到了使用简单html dom提取数据的方法,但它给了我以下错误: 警告: 文件获取内容(): 无法打开流:HTTP请求失败!HTTP/1.1500服务器错误 在C:\Users\Abhishek\Desktop\editor\request\simple\u html\u dom.php中 第75行 致命错误:对中的布尔值调用成员函数find() 第9行的C:\Users\Abhishek\Desktop\editor\request\main.php 我为此设计的php代码是:Php 使用简单html dom从网页中提取值,php,html,web-scraping,file-get-contents,Php,Html,Web Scraping,File Get Contents,我在网上搜索并找到了使用简单html dom提取数据的方法,但它给了我以下错误: 警告: 文件获取内容(): 无法打开流:HTTP请求失败!HTTP/1.1500服务器错误 在C:\Users\Abhishek\Desktop\editor\request\simple\u html\u dom.php中 第75行 致命错误:对中的布尔值调用成员函数find() 第9行的C:\Users\Abhishek\Desktop\editor\request\main.php 我为此设计的php代码是:
<?php
include('simple_html_dom.php');
$html = file_get_html('http://www.flipkart.com/moto-g-2nd-gen/p/itme6g3wferghmv3');
foreach($html->find('span.selling-price.omniture-field') as $e)
echo $e->outertext . '<br>';
?>
我是这个程序的新手,没有足够的知识,但我的程序中有错误吗?请确保启用了此功能。。发件人:
如果已启用fopen包装器,则URL可以用作此功能的文件名
由于禁用了此功能,因此文件\u get\u contents()
返回false
,这将导致第二个错误 确保已启用此功能。。发件人:
如果已启用fopen包装器,则URL可以用作此功能的文件名
由于禁用了此功能,因此
文件\u get\u contents()
返回false
,这将导致第二个错误 服务器可能基于用户代理拒绝您的请求,请尝试使用curl获取页面html,即
<?php
$url="http://www.flipkart.com/moto-g-2nd-gen/p/itme6g3wferghmv3";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_USERAGENT, "User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_ENCODING, "");
$pagebody=curl_exec($ch);
curl_close ($ch);
include('simple_html_dom.php');
$html = str_get_html($pagebody);
foreach($html->find('.selling-price') as $e)
echo $e->outertext . '<br>';
服务器可能基于用户代理拒绝您的请求,请尝试使用curl获取页面html,即
<?php
$url="http://www.flipkart.com/moto-g-2nd-gen/p/itme6g3wferghmv3";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_USERAGENT, "User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_ENCODING, "");
$pagebody=curl_exec($ch);
curl_close ($ch);
include('simple_html_dom.php');
$html = str_get_html($pagebody);
foreach($html->find('.selling-price') as $e)
echo $e->outertext . '<br>';
<代码>仍然没有返回价格。我已经更新了我的答案,如果它帮助你,请考虑投票1 +并接受它作为正确答案通过点击中间的投票箭头,TKS!但它没有返回价格。我已经更新了我的答案,如果它帮助你,请考虑投票1 +,并接受它作为正确答案,通过点击中间的投票箭头,TKS!