Меню сайта
Категории раздела
Мини-чат
Наш опрос
Урок fake4
Поиск
Урок fake5
Теги
Витрина ссылок
Главная » Файлы » Уроки php DevelStudio |
Урок 14. Граббим информацию с сайта
11.10.2011, 16:00 | |
Сейчас вам расскажу как граббить инфу ( в данном случае IP с сайта 2ip.ru)
для этого нам нужно 1 - то что нам нужно сграбить 2 - откуда мы будим граббить то что нам нужно ~~~ 1 - в данном случае мой IP 178.45.144.181 2 - http://2ip.ru так теперь добавим функцию коннект через кёрл, выглядит это так PHP код: ·········10········20········30········40········50········60········70········80········90········100·······110·······120·······130·······140·······150 <br> function connect($link){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$link); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt($ch, CURLOPT_TIMEOUT, 10 ); curl_setopt($ch, CURLOPT_GET, 1 ); curl_setopt($ch, CURLOPT_HEADER, 1 ); curl_setopt($ch, CURLOPT_COOKIE, $cookie); $otvet = curl_exec($ch); curl_close($ch); return $otvet;} 01. 02. 03. 04. 05. 06. 07. 08. 09. 10. 11. так .. теперь мы берём ссылку на страницу с которой будем граббить и добавляем её в скрипт под переменной $link и пришиваем с кёрла $otvet PHP код: ·········10········20········30········40········50········60········70········80········90········100·······110·······120·······130·······140·······150 <br> function connect($link){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$link); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt($ch, CURLOPT_TIMEOUT, 10 ); curl_setopt($ch, CURLOPT_GET, 1 ); curl_setopt($ch, CURLOPT_HEADER, 1 ); curl_setopt($ch, CURLOPT_COOKIE, $cookie); $otvet = curl_exec($ch); curl_close($ch); return $otvet;} $link = http: //2ip.ru/'; $otvet=connect($link); 01. 02. 03. 04. 05. 06. 07. 08. 09. 10. 11. 12. 13. 14. ура! мы соеденились с сервером о_О терь дело за граббингом код для сграбливания я расписывать не буду .. берите уже готовый и пользуйтесь на здоровьё ^_^ PHP код: ·········10········20········30········40········50········60········70········80········90········100·······110·······120·······130·······140·······150 $begin = 'пишите тут то что стоит перед тем что нам нада сграбить' ; $begin = strpos($otvet, $begin) + strlen($begin); $end = 'сдесь пишем то что стоит после того что нам нада сграбить' ; $end = strpos($otvet, $end, $begin); $lc = substr($otvet, $begin, $end - $begin); <br> 1. 2. 3. 4. 5. 6. пример : если нам надо грабить IP 178.45.144.181 с страницы http://2ip.ru/ смотрим исходный код страницы и находим IP 178.45.144.181 Код HTML: [code]</span> <big>178.45.144.181</big> <!--<a href="" title="">Что ещё можно узнать об IP-адресе?</a>--> <div class="notepad" onclick="javascript:showEffectBlock('notepadBlock')" > видим что число 178.45.144.181 [/code] запихнуто в <big> и </big> тогда у нас получится PHP код: ·········10········20········30········40········50········60········70········80········90········100·······110·······120·······130·······140·······150 <br> function connect($link){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$link); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt($ch, CURLOPT_TIMEOUT, 10 ); curl_setopt($ch, CURLOPT_GET, 1 ); curl_setopt($ch, CURLOPT_HEADER, 1 ); curl_setopt($ch, CURLOPT_COOKIE, $cookie); $otvet = curl_exec($ch); curl_close($ch); return $otvet;} $link = 'http://2ip.ru/' ; $otvet = connect($link); $begin = '<big>' ; $begin = strpos($otvet, $begin) + strlen($begin);<br>$end = '</big>' ; $end = strpos($otvet, $end, $begin); $lc = substr($otvet, $begin, $end - $begin); 01. 02. 03. 04. 05. 06. 07. 08. 09. 10. 11. 12. 13. 14. 15. 16. 17. 18. вот и всё ... сграббили .. но как вывести на экран ?! PHP код: ·········10········20········30········40········50········60········70········80········90········100·······110·······120·······130·······140·······150 c( "edit1" )->text = $lc;<br> 1. урок готов желаю удачи вам юные скриптописатели Создадим на форму "кнопку" и "поле ввода" В нопку вставим следующий текст ·········10········20········30········40········50········60········70········80········90········100·······110·······120·······130·······140·······150 function connect($link){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$link); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt($ch, CURLOPT_TIMEOUT, 10 ); curl_setopt($ch, CURLOPT_GET, 1 ); curl_setopt($ch, CURLOPT_HEADER, 1 ); curl_setopt($ch, CURLOPT_COOKIE, $cookie); $otvet = curl_exec($ch); curl_close($ch); return $otvet; } $link = 'http://2ip.ru/' ; $otvet = connect($link); $begin = '<big>' ; $begin = strpos($otvet, $begin) + strlen($begin); $end = '</big>' ; $end = strpos($otvet, $end, $begin); $lc = substr($otvet, $begin, $end - $begin); c( "edit1" )->text = $lc; 01. 02. 03. 04. 05. 06. 07. 08. 09. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. Автор : Resh Специально для DevelStudio.3dn.ru Комментируем активнее.
Автор: Не указан
Источник: Не указан | |
Просмотров: 4616 | Загрузок: 0 | Комментарии: 3 | Рейтинг: 1.0/1 |
Всего комментариев: 3 | |
| |