I am using simple_html_dom.php library from this example
http://nimishprabhu.com/top-10-best-usage-examples-php-simple-html-dom-parser.html
But i got error 500 inside class, when I type url in browser it works ok?
I have some vaules in array like this
$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 ) )
When I try something like this
foreach($result as $key => $value) {
$xmlFind = file_get_html($value['href']);
foreach($xmlFind->find('a') as $a) {
echo '<p>'.$a->href.'</p>';
}
}
I got error
A PHP Error was encountered Severity: Warning Message: file_get_contents(http://zh.powernet.ch/webservices/inet/HRG/HRG.asmx/getHRGHTML?chnr=0203038402&amt=020&toBeModified=0&validOnly=0&lang=1&sort=0): failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error Filename: libraries/Simple_html_dom.php Line Number: 76
But when I try manually like this
$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');
Result is there, also if i type that url i browser all is ok, only problem i have is when i try to loop an array ??
The web scraping can be done by targeting the selected DOM components and then processing or storing the text between that DOM element of a web page. To do the same in PHP, there is an API which parses the whole page and looks for the required elements within the DOM. It is the Simple HTML DOM Parser.
The DOMParser interface provides the ability to parse XML or HTML source code from a string into a DOM Document . You can perform the opposite operation—converting a DOM tree into XML or HTML source—using the XMLSerializer interface.
PHP Simple HTML DOM ParserA fast, simple and reliable HTML document parser for PHP. Created by S.C. Chen, based on HTML Parser for PHP 4 by Jose Solorzano.
check http://php.net/manual/en/function.file-get-contents.php Notes section.
Please check your server settings for "fopen wrappers"
I tried the following
<?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>';
}
}
And got this
#
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:[email protected]
Proxy might be a problem. Use appropriate proxy.
// 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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With