Robert Sinclair
Robert Sinclair

Reputation: 5426

SSL operation failed with code 1 "PHP Simple HTML DOM Parser"

I'm trying to scrape a https page with the following snippet using the "PHP Simple HTML DOM Parser" library:

$html = file_get_html('https://domain.com/');

But it's throwing an error

SSL operation failed with code 1

I want to nuke verification as per file_get_contents(): SSL operation failed with code 1. And more , the solution was to add this:

    $arrContextOptions=array(
    "ssl"=>array(
    "verify_peer"=>false,
    "verify_peer_name"=>false,
    ),
);  

But I'm not sure what to change within the library's function:

function file_get_html($url, $use_include_path = false, $context=null, $offset = -1, $maxLen=-1, $lowercase = true, $forceTagsClosed=true, $target_charset = DEFAULT_TARGET_CHARSET, $stripRN=true, $defaultBRText=DEFAULT_BR_TEXT, $defaultSpanText=DEFAULT_SPAN_TEXT)

or is it something I should be adding here?:

$dom = new simple_html_dom(null, $lowercase, $forceTagsClosed, $target_charset, $stripRN, $defaultBRText, $defaultSpanText);

$contents = file_get_contents($url, $use_include_path, $context, $offset);

Sorry I know it's probably a simple solution but I've been scratching my head for the past 3 hours trying to figure this out.

Upvotes: 1

Views: 4144

Answers (1)

Erik Leisch
Erik Leisch

Reputation: 96

If you paste the following right after the open curly brace for the file_get_html function, it will work:

$context = stream_context_create(
    array(
        'http' => array(
            'follow_location' => false
        ),
        'ssl' => array(
            "verify_peer"=>false,
            "verify_peer_name"=>false,
        ),
    )
);

enter image description here

Upvotes: 8

Related Questions