Rumah  >  Soal Jawab  >  teks badan

Ralat maut: Ralat tidak ditangkap: Memanggil fungsi ahli find() pada bool dalam C Surih tindanan: #0 {utama} dilemparkan dalam C pada baris 16

Saya mendapat ralat ini di atas dan kod saya di bawah. Adakah terdapat apa-apa yang salah dengan kod saya? Sebarang bantuan amat dihargai. Saya tidak pasti sama ada ia ada kaitan dengan perisian yang saya gunakan untuk menjalankannya, XAMPP Apache. Saya sedang cuba mendapatkan maklumat daripada halaman web yang mengandungi kod produk dalam Excel. Saya berjaya menjalankan sekitar 900+ kod pengeluaran tetapi tiba-tiba saya mendapat ralat di atas.

<?php
// example of how to use basic selector to retrieve HTML contents
include('simple_html_dom.php');

$file = fopen("Book1.csv","r");
$file2 = fopen("test.csv","w");
$links = [];

while (($result = fgetcsv($file)) !== false)
{
    $link = "https://mall/Product/".$result[0];
    $links[] = $link;

    $row_data = [];
    $page = file_get_html($link);
    $product_details = $page->find('.ProductDetailsTable tr'); //line 16
    if(count($product_details)==0) {
        $row_data[] = $result[0];
        $row_data[] = 'not found'; 
        fputcsv($file2, $row_data);
        continue;
    }

    //second method
    $article_number = '';
    $product_description = '';
    $product_family = '';
    $product_lifecycle = '';
    $plm_date = '';
    $notes = '';
    $EAN = '';
    $UPC = '';
    $country_of_origin = '';

    foreach($product_details as $table_row) {    
        if(count($table_row->find('td'))==1){
            //ignore
        } elseif(count($table_row->find('td'))==2) {
            $key = $table_row->find('td')[0]->plaintext;
            $value = $table_row->find('td')[1]->plaintext;
            if($key=="EAN") {
                $EAN = $value;
            }
            elseif($key=='Article Number (Market Facing Number)') {
                $article_number = $value;
            } elseif ($key=='Product Description') {
                $product_description = $value;
            } elseif ($key=='Product family') {
                $product_family = $value;
            }elseif ($key=='Product Lifecycle (PLM)') {
                $product_lifecycle = $value;
            }elseif ($key=='PLM Effective Date') {
                $plm_date = $value;
            }elseif ($key=='Notes') {
                $notes = $value;
            }elseif ($key=='UPC') {
                $UPC = $value;
            }elseif ($key=='Country of origin') {
                $country_of_origin = $value;
            }    
        } 
    }
    $row_data[] = trim($article_number);
    $row_data[] = trim($product_description);
    $row_data[] = trim($product_family);
    $row_data[] = trim($product_lifecycle);
    $row_data[] = trim($plm_date);
    $row_data[] = trim($notes);
    $row_data[] = trim($EAN);
    $row_data[] = trim($UPC);
    $row_data[] = trim($country_of_origin);
    fputcsv($file2, $row_data);
}

fclose($file);
fclose($file2);
echo 'done';

?>

P粉878510551P粉878510551270 hari yang lalu375

membalas semua(1)saya akan balas

  • P粉237647645

    P粉2376476452023-12-29 23:12:44

    Ini berlaku file_get_html() 返回一个布尔值(可能是 false disebabkan beberapa ralat seperti url tidak sah).

    Kod anda tidak mempunyai kegagalan semakan.

    Saya cadangkan anda menambah yang berikut:

    if (!$page) {
      // Do some error handling, logging
      continue; // skip to next iteration on your loop.
    }

    balas
    0
  • Batalbalas