我使用的是本例中的simple_html_dom.php库
http://nimishprabhu.com/top-10-best-usage-examples-php-simple-html-dom-parser.html
但是我在类里面得到了错误500,当我在浏览器中输入url的时候,它能正常工作吗?
我在数组中有一些值,如下所示
$result= Array (
[Avenya Group AG] =>
Array (
[link] => CHE-218.938.800
[href] => http://zh.powernet.ch/webservices/inet/HRG/HRG.asmx/getHRGHTML?chnr=0203038402&amt=020&toBeModified=0&validOnly=0&lang=1&sort=0 ) )
当我尝试这样的事情时
foreach($result as $key => $value) {
$xmlFind = file_get_html($value['href']);
foreach($xmlFind->find('a') as $a) {
echo '<p>'.$a->href.'</p>';
}
}
我弄错了
HTTP遇到错误严重程度:警告消息: file_get_contents():无法打开流:请求失败!HTTP/1.1500内部服务器错误文件名: libraries/Simple_html_dom.php行号: 76
但是当我像这样手动尝试的时候
$xmlFind = file_get_html('http://zh.powernet.ch/webservices/inet/HRG/HRG.asmx/getHRGHTML?chnr=0203038402&amt=020&toBeModified=0&validOnly=0&lang=1&sort=0');
结果是存在的,如果我输入url,浏览器一切正常,唯一的问题是当我尝试循环一个数组时??
发布于 2015-12-08 20:26:53
查看http://php.net/manual/en/function.file-get-contents.php备注部分。
请检查"fopen wrappers“的服务器设置
我尝试了以下几种方法
<?php
include('simple_html_dom.php');
$result= Array (
'Avenya Group AG' =>
Array (
'link' => 'CHE-218.938.800',
'href' => 'http://zh.powernet.ch/webservices/inet/HRG/HRG.asmx/getHRGHTML?chnr=0203038402&amt=020&toBeModified=0&validOnly=0&lang=1&sort=0' ) );
foreach($result as $key => $value) {
$xmlFind = file_get_html($value['href']);
foreach($xmlFind->find('a') as $a) {
echo '<p>'.$a->href.'</p>';
}
}
然后得到了这个
#
http://www.shab.ch/shabforms/servlet/Search?EID=7&DOCID=6890948
http://www.shab.ch/shabforms/servlet/Search?EID=7&DOCID=981331
http://zh.powernet.ch/webservices/inet/hrg/hrg.asmx/getExcerpt?Chnr=CH-020.3.038.402-5&Amt=20&Lang=1
mailto:info@powernet.ch
发布于 2015-12-13 01:36:32
代理可能是个问题。使用适当的代理。
// Create a stream
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: en\r\n" .
"Cookie: foo=bar\r\n",
'proxy' => 'tcp://221.176.14.72:80',
)
);
$context = stream_context_create($opts);
// Open the file using the HTTP headers set above
$file = file_get_contents('http://ifconfig.me/ip', false, $context);
var_dump($file);
发布于 2015-12-12 13:30:04
尝尝这个,
<?php
$result= Array (
'Avenya Group AG' =>
Array (
'link' => 'CHE-218.938.800',
'href' => 'http://zh.powernet.ch/webservices/inet/HRG/HRG.asmx/getHRGHTML?chnr=0203038402&amt=020&toBeModified=0&validOnly=0&lang=1&sort=0'
)
);
foreach($result as $arr_item){
if(is_array($arr_item)) {
if(isset($arr_item['href'])) {
echo file_get_contents($arr_item['href']);
}
}
}
?>
在执行上面的代码后,我得到了这个响应,如所附图像所示。
如果仍然收到警告错误,可以使用curl发送get请求。因此,不使用上面的echo file_get_contents($arr_item['href']);
将其替换为以下代码。
$ch = curl_init($arr_item['href']);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
$result = curl_exec($ch);
echo $result;
curl_close($ch);
https://stackoverflow.com/questions/34115921
复制相似问题