Y
Y
YourKey2014-01-30 17:35:44
PHP
YourKey, 2014-01-30 17:35:44

Why is 2 copies of the results written during parsing (Simple html dom)?

Hello! I wrote a simple parser that will iterate over the table and write links, 30 links per page, and then flip the page and write again. I used the simple html dom library with output to the database. The matter is that 2 copies of a line register in the table. I am not strong in php, so I can not figure out where the error is. I am attaching the code:

<?php
include('simple_html_dom.php');
$url = "domain.ru/html?page=";

for ($i = 1; $i < 30; $i++) {
// парсим первые 30 страниц
  $html = file_get_html($url.$i) or die ("Сайт недоступен");  
  $s1 = $html->find('table',9);
    for ($n = 0; $n <=29; $n++) { // 30 строк в таблице
        // парсим ссылку из href
        $link = $s1->find('td[width=100%] a[name]',$n)->href;
        $link = str_replace('/', '', $link);
        $link = str_replace('http:', '', $link);
        $s2['link'] = $link;
        // Записываем в двумерный массив
        $datas["$link"] = $s2;
        
        
        // записываем в бд
        $sql="INSERT INTO `parse` ( link ) values
        (
        '". mysql_real_escape_string($datas["$link"]['link'])."',
        )";
        $res=mysql_query($sql);
        if (!$res) {
        die('Invalid query: ' . mysql_error());
        }			
    }
}
?>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question