function parseItems($links = null) { $page = get_hero_page("http://dota2.ru/items/"); // Получение страницы и создание объекта из ее html if ($page['error_no'] != 0) { echo "Ошибка получения страницы героя</br>" . $page['error'] . "</br>"; die; } else { $html = $page["page"]; } $document = phpQuery::newDocument($html); // Получение страницы и создание объекта из ее html if (is_null($links)) { $item_links_with_info = $document->find("#list > .item > a"); } else { foreach ($links as $link) { $item_links_with_info[] = $document->find("#list > .item > a[href='" . trim($link) . "']"); } } foreach ($item_links_with_info as $item_link) { file_put_contents(__DIR__ . "/logs/parse_ithems.log", date("Y-m-d H:i:s") . ": начинаю парсить предмет" . $item_link->attr('href') . "\r\n", FILE_APPEND); $item_html_obj = pq($item_link); $img_src = $item_html_obj->find('.tooltipe')->attr('src'); $name_and_slug = item_img_name_and_slug(trim($img_src)); $item['slug'] = mysql_real_escape_string($name_and_slug["slug"]); $path = "/images/ithems/" . $name_and_slug["filename"] . ".jpg"; $img_link = "http://dota2.ru" . $img_src; if (download_img_in_folder($img_link, $path)) { $item['image'] = mysql_real_escape_string($path); } else { continue; } $item['info'] = get_item_info($item_html_obj->find('.tooltipe-content')); $items[] = $item; } take_items_to_bd($items); }
function changeNames() { $result = mysql_query("SELECT id, name, slug FROM heroes"); while ($hero = mysql_fetch_array($result)) { echo $hero['id'] . "</br>" . $hero['name'] . "</br>" . $hero['slug'] . "</br>"; $link = "http://dota2.ru/heroes/" . $hero['slug']; $query = get_hero_page($link); if ($query['error'] != 0) { echo "Ошибка получения страницы героя</br>"; break; } else { $page = $query["page"]; } $document = phpQuery::newDocument($page); $name = $document->find(".p-header > h1")->text(); if (mysql_query("UPDATE heroes SET name='{$name}' WHERE id='{$hero['id']}'")) { echo "Имя героя - " . $hero['slug'] . " обновлено на - " . $name; } else { echo "Имя не удалось обновить. Ошибка в запросе. " . mysql_error(); } echo "</br></br>"; sleep(20); } }
function parseHeroes($file) { $links = get_links_from_file($file); foreach ($links as $link) { file_put_contents(__DIR__ . "/logs/parse_heroes.log", date("Y-m-d H:i:s") . ": Начинаю парсить героя '" . $link . "'\r\n", FILE_APPEND); $page = get_hero_page($link); if ($page['error_no'] != 0) { file_put_contents(__DIR__ . "/logs/parse_heroes.log", date("Y-m-d H:i:s") . ": Ошибка получения страницы '" . $link . "' " . $page['error'] . "\r\n", FILE_APPEND); return; } else { $html = $page["page"]; } $hero['info'] = get_hero_main_info($html); $hero['skills'] = get_hero_skills($hero['info']['slug'], $html); $hero_id = add_new_hero($hero['info']); add_hero_skills($hero['skills'], $hero_id, $hero['info']['slug']); sleep(30); } }