Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php]Spider na własną stronę.
Mike122
post
Post #1





Grupa: Zarejestrowani
Postów: 253
Pomógł: 1
Dołączył: 12.04.2006

Ostrzeżenie: (0%)
-----


Potrzebuję stworzyć sobie "bota" który znajdzie wszystkie strony tylko w moim serwisie.
Więc po przeczytaniu paru różnych tematów na forach stworzyłem kod który znajduje linki i wyświetla je.
jednak posiadam pewien problem jak zrobić aby nie wyświetlał 4 czy 6 razy tych samych linków.
Chodzi mi żeby był raz 1 link.

  1. <?php
  2. $url = "index.html";
  3. $link = implode('', file($url));
  4. if(preg_match_all('/<a[^>]+?hrefs*?=s*?("|')?(.*?)(?(1)1[^>]*>|(?:s[^>]*>|>))(.*?)</a>/si', $link, $sub)){
  5. foreach($sub[2] as $value){
  6. if (!eregi('http://', $value)) {
  7. $link = implode('', file($value));
  8. if(preg_match_all('/<a[^>]+?hrefs*?=s*?("|')?(.*?)(?(1)1[^>]*>|(?:s[^>]*>|>))(.*?)</a>/si', $link, $sub)){
  9. foreach($sub[2] as $value){
  10. if (!eregi('http://', $value)){
  11. echo ($value);
  12. echo ("<br />");
  13. }
  14. }
  15. }
  16. }
  17. }
  18. }
  19. }
  20. ?>

Uwagi i propozycje do do zamiany jakiś funkcji mile widziane. Pozdrawiam i proszę o pomoc.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Mike122
post
Post #2





Grupa: Zarejestrowani
Postów: 253
Pomógł: 1
Dołączył: 12.04.2006

Ostrzeżenie: (0%)
-----


Zrobiłem tak jak radziliście i nic już nie wyświetla (IMG:http://forum.php.pl/style_emoticons/default/tiredsmiley.gif)
  1. <?php
  2. $web = "index.html";
  3. $web = implode('', file($web));
  4. if(preg_match_all('/<a[^>]+?hrefs*?=s*?("|')?(.*?)(?(1)1[^>]*>|(?:s[^>]*>|>))(.*?)</a>/si', $web, $sub)){
  5. foreach($sub[2] as $url){
  6. if(!eregi("http://", $url)){
  7. if(!in_array($url, $sub[2])){
  8. $web = implode('', file($url));
  9. if(preg_match_all('/<a[^>]+?hrefs*?=s*?("|')?(.*?)(?(1)1[^>]*>|(?:s[^>]*>|>))(.*?)</a>/si', $web, $sub)){
  10. foreach($sub[2] as $url){
  11. if (!eregi("http://", $url)){
  12. if(!in_array($url, $sub[2])){
  13. echo ($url);
  14. echo ("<br />");
  15. }
  16. }
  17. }
  18. }
  19. }
  20. }
  21. }
  22. }
  23. ?>


Po zabraniu znaku !
  1. <?php
  2. if(!in_array($url, $sub[2])){
  3. echo ($url);
  4. echo ("<br />");
  5. }
  6. ?>

Wyświetla tak jak przedtem wszytko. (IMG:http://forum.php.pl/style_emoticons/default/sadsmiley02.gif)
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 8.10.2025 - 09:40