A
A
artemka1706912022-01-19 10:27:05
PHP
artemka170691, 2022-01-19 10:27:05

How to fix ssl is blocking the simple_html_dom parser?

Tell me how to apply code No. 1 to my No. 2, I have tried all the options already. The parser is being blocked by ssl.
Code #1:

$arrContextOptions=array(
    "ssl"=>array(
        "verify_peer"=>false,
        "verify_peer_name"=>false,
    ),
);
$html = file_get_html("https://new.starbyte.ru/article/{PRODUCT_ID}", false, stream_context_create($arrContextOptions));


Code #2:
<?php
namespace Supplier;
use Model\Supplier;
defined('PIMPORT') or die('Error access');
/**
 * Class NEWW
 * @package Supplier
 */
class NEWW extends \Infr\Supplier {
    /** @var string */
    protected $_host = 'https://new.starbyte.ru';
    /** @var string */
    protected $_productMask = 'https://new.starbyte.ru/article/{PRODUCT_ID}';
    protected function _getPrice() {
        //проверяем подключен ли плагин и к нему поставщик
        $class = 'Plugins\Suppliers\Supplier\NEWW';
        if (class_exists($class)) {
            /** @var \Plugins\Suppliers\Infr\Supplier $supplierItem */
            $supplierItem = new $class;
            $pricePath = $supplierItem->getPricePath();
            if (file_exists($pricePath)) {
                return file_get_contents($pricePath);
            } else {
                throw new \Exception('Прайс-лист для поставщика не загружен');
            }
        } else {
            throw new \Exception('К плагину Suppliers не подключен нужный поставщик');
        }
    }
    public function getProduct(Supplier $supplier, Supplier\Product $product, array $params = array()) {
        if ($product->url) {
            $html = \Infr\Request::httpRequest($product->url);			
      if ($html) {
        $dom = \Infr\str_get_html($html);
        if ($dom) {
          $pics = $dom->find('.photos a');
if ($pics) {
foreach($pics as $pic) {
$product->pictures[] = 'http:'.$pic->getAttribute('href');
}
}
                    $techpars = $dom->find('.tab-content', 0);                        
             if ($techpars){
$techpars = preg_replace("!<a class=\"link\"(.*?)>(.*?)</a>!si","\\2",$techpars); //Удаление ссылок
$techpars = preg_replace("!<a(.*?)>(.*?)</a>(.*?)</nobr>!si","\\2",$techpars); //Удаление ссылки PDF
                         $desc = $techpars;
                         $product->description = $desc;
             
                         }        
          unset($dom);
        }
      }
            unset($html);
        }

        return $product;
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
rPman, 2022-01-19
@rPman

load the page manually with the same curl and feed the line to the parser using the str_get_html method

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question