R
R
ree4i2015-09-08 17:19:23
PHP
ree4i, 2015-09-08 17:19:23

Parsing error, help?

My code:

set_time_limit(0);
ini_set( 'memory_limit', '256M' );

include $_SERVER['DOCUMENT_ROOT']."/simple_html_dom.php";

function parse($url){
  $uagent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)"; 
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_USERAGENT, $uagent);
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
  curl_setopt($ch, CURLOPT_COOKIEJAR,$_SERVER['DOCUMENT_ROOT']."/data/cookie.txt");
  curl_setopt($ch, CURLOPT_COOKIEFILE,$_SERVER['DOCUMENT_ROOT']."/data/cookie.txt");
  $data = iconv('CP1251', 'UTF-8', curl_exec($ch));
  curl_close($ch);
  return $data;
}

echo str_get_html(parse($url));

Displays above the parser page:
Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

    Line 343:        string AcceptEncoding = HttpContext.Current.Request.Headers["Accept-Encoding"];  Line 344:  Line 345:        if (!string.IsNullOrEmpty(AcceptEncoding) &&  Line 346:  Line 347:             AcceptEncoding.Contains("gzip") || AcceptEncoding.Contains("deflate"))


Source File: d:\inetpub\vhosts\filmitena.com\httpdocs\MasterPage.master.cs    Line: 345

Stack Trace:

    [NullReferenceException: Object reference not set to an instance of an object.]     MasterPage.IsGZipSupported() in d:\inetpub\vhosts\sdgf.com\httpdocs\MasterPage.master.cs:345     MasterPage.GZipEncodePage() in d:\inetpub\vhosts\sdgf.com\httpdocs\MasterPage.master.cs:319     MasterPage.Page_Load(Object sender, EventArgs e) in d:\inetpub\vhosts\sdgf.com\httpdocs\MasterPage.master.cs:25     System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51     System.Web.UI.Control.OnLoad(EventArgs e) +92     System.Web.UI.Control.LoadRecursive() +54     System.Web.UI.Control.LoadRecursive() +145     System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772  

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34249

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
ree4i, 2015-09-08
@ree4i

That's it, the question is answered, the drowning man pulled himself out by the hair ))
It turned out that the convenient iconv goes to hell, and CURLOPT_ENCODING comes into play instead)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question