IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Web Perl Discussion :

Reconstruction d'url


Sujet :

Web Perl

  1. #1
    Membre actif Avatar de mobscene
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    331
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2005
    Messages : 331
    Points : 234
    Points
    234
    Par défaut Reconstruction d'url
    Voila je me suis fait un ti script pour lire les fichiers robots.txt , parce que je n'est pas réussie a faire a www::robotrules me sortire dans url complète

    Voci mon code


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    #!C:\Perl\bin\perl.exe
     
     
    @EE = ("http://www.google.com/robots.txt");
     
    @EE = find(@EE);
     
     
    sub find(@)
    {
     my @EE = @_;
    use LWP::Simple;
    for my $URL( @EE ) {
        my $B = get($URL);
        return $B;
      }
    }
     
     
     
    print "@EE";
    print "\n";
    print "----------------------------------------\n";
    for $T( @EE ) {
     $T =~ s/Allow.*//g;
     print "$T";
    }
    je cherche a recontruire les url dans le cas de google a obtnir ceci

    http://www.google.com/search
    http://www.google.com/groups
    http://www.google.com/images
    http://www.google.com/catalogs
    http://www.google.com/catalog_list
    http://www.google.com/news
    http://www.google.com/nwshp
    http://www.google.com/?
    http://www.google.com/addurl/image?
    http://www.google.com/pagead/
    http://www.google.com/relpage/
    http://www.google.com/sorry/
    http://www.google.com/imgres
    http://www.google.com/keyword/
    http://www.google.com/u/
    http://www.google.com/univ/
    http://www.google.com/cobrand
    http://www.google.com/custom
    http://www.google.com/advanced_group_search
    http://www.google.com/advanced_search
    http://www.google.com/googlesite
    http://www.google.com/preferences
    http://www.google.com/setprefs
    http://www.google.com/swr
    http://www.google.com/url
    http://www.google.com/wml?
    http://www.google.com/xhtml?
    http://www.google.com/imode?
    http://www.google.com/jsky?
    http://www.google.com/pda?
    http://www.google.com/sprint_xhtml
    http://www.google.com/sprint_wml
    http://www.google.com/pqa
    http://www.google.com/palm
    http://www.google.com/hws
    http://www.google.com/bsd?
    http://www.google.com/linux?
    http://www.google.com/mac?
    http://www.google.com/microsoft?
    http://www.google.com/unclesam?
    http://www.google.com/answers/search?q=
    http://www.google.com/local?
    http://www.google.com/local_url
    http://www.google.com/froogle?
    http://www.google.com/froogle_
    http://www.google.com/print?
    http://www.google.com/scholar?
    http://www.google.com/complete
    http://www.google.com/sponsoredlinks
    http://www.google.com/videosearch?
    http://www.google.com/videopreview?
    http://www.google.com/videoprograminfo?
    http://www.google.com/maps?
    http://www.google.com/translate?
    http://www.google.com/ie?
    http://www.google.com/sms/demo?

    J'ai testé divers soluce a base de regXp mais la je rame trop donc Help
    Everybody have in their the potential to be their own god : Marilyn Manson

  2. #2
    Membre actif
    Inscrit en
    Février 2005
    Messages
    167
    Détails du profil
    Informations forums :
    Inscription : Février 2005
    Messages : 167
    Points : 203
    Points
    203
    Par défaut
    Il me semble que c'est plutôt :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    $T =~ s/{Disallow: (\S+)}{http://www.google.com$1}
    qui va faire ce que tu cherches.

    N

  3. #3
    Membre actif Avatar de mobscene
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    331
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2005
    Messages : 331
    Points : 234
    Points
    234
    Par défaut
    $T =~ s/{Disallow: (\S+)}{http://www.google.com$1}
    marche pas



    le truc c'est que je connais pas les valeurs de @EE
    Everybody have in their the potential to be their own god : Marilyn Manson

  4. #4
    Membre actif Avatar de mobscene
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    331
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2005
    Messages : 331
    Points : 234
    Points
    234
    Par défaut
    Voila ou j'en suis


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    #!C:\Perl\bin\perl.exe
     
     
    @EE = ("http://www.google.com/robots.txt");
     
    @EE = find(@EE);
     
     
    sub find(@)
    {
     my @EE = @_;
    use LWP::Simple;
    for my $URL( @EE ) {
        my $B = get($URL);
        return $B;
      }
    }
     
     
     
    #print "@EE";
    #print "\n";
    #print "----------------------------------------\n";
    for $T( @EE ) {
    $T =~ s/User-agent: \*//ig;
    $T =~ s/Allow.*//g;
    $T =~ s/Disallow: /{Disallow: (\S+)}{http:\/\/www\.google\.com\/$1}/ig;
    $T =~ s/\{//ig;
    $T =~ s/\}//ig;
    $T =~ s/\(S\+\)//ig;
    $T =~ s/.*Disallow: //ig;
    $T =~ s/\/\//\//ig;
    $T =~ s/http:\//http:\/\//ig;
     print "$T";
    }

    $T =~ s/Disallow: /{Disallow: (\S+)}{http:\/\/www\.google\.com\/$1}/ig;
    par contre faudrais changer le regXp pour qu'il marche avec @EE
    Everybody have in their the potential to be their own god : Marilyn Manson

  5. #5
    Membre actif Avatar de mobscene
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    331
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2005
    Messages : 331
    Points : 234
    Points
    234
    Par défaut
    Il ne me reste qu'un problème c'est comment backslashé les caractères réservé des RegXp


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    #!C:\Perl\bin\perl.exe
     
     
    @EE = ("http://www.google.com/robots.txt");
     
    @EE = find(@EE);
     
     
    sub find(@)
    {
     my @EE = @_;
    use LWP::Simple;
    for my $URL( @EE ) {
        my $B = get($URL);
        return $B;
      }
    }
     
     
    @EE = replace(@EE);
    print "@EE";
     
     
     
    sub replace(@)
    {
    @EE = @_;
     
    for $Z( @EE )
    {
      # Backslaché les caractères réservés
    }
     
     
     
     
     
    for $T( @EE ) {
    $T =~ s/User-agent: \*//ig;
    $T =~ s/Allow.*//g;
     
    #   Remplacement
    $T =~ s/Disallow: /{Disallow: (\S+)}{$Z\/$1}/ig; #$Z et hop sa marche
    $T =~ s/\{//ig;
    $T =~ s/\}//ig;
    $T =~ s/\(S\+\)//ig;
    $T =~ s/.*Disallow: //ig;
    $T =~ s/\/\//\//ig;
    $T =~ s/http:\//http:\/\//ig;
    # print "$T";
    return $T;
    $T = ();
     }
    }
    Everybody have in their the potential to be their own god : Marilyn Manson

  6. #6
    Membre actif Avatar de mobscene
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    331
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2005
    Messages : 331
    Points : 234
    Points
    234
    Par défaut
    Personne veut m'aider pour ce regXp a la c** il faut en fait backslashé les / et . dans $Z
    Everybody have in their the potential to be their own god : Marilyn Manson

  7. #7
    Membre actif
    Inscrit en
    Février 2005
    Messages
    167
    Détails du profil
    Informations forums :
    Inscription : Février 2005
    Messages : 167
    Points : 203
    Points
    203
    Par défaut
    mais tu te fiches de les backslasher. A quoi ça sert ?

    N

  8. #8
    Membre actif Avatar de mobscene
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    331
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2005
    Messages : 331
    Points : 234
    Points
    234
    Par défaut
    Heu oui c'etait une erreur. Bon j'ai encore un prb avant de faire le ménage dans le prog

    Le script marche bien seulement il ne me retourne que le premier élément du tableau


    Voici le code :


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    #!C:\Perl\bin\perl.exe
     
    # ATTENTTION PAS PROPRE
     
    @EE = ("http://www.google.com/robots.txt","http://search.msn.fr/robots.txt");
     
    for $X( @EE ) {
     
    @EE = find(@EE);
     
    @EE = replace(@EE);
    print "@EE"; # Récupération de robotx.txt
     
     
     
    sub find(@)
    {
     my @EE = @_;
    use LWP::Simple;
    for my $URL( @EE ) {
        my $B = get($URL);
        return $B;
      }
    }
     
     
    sub replace(@)
    {
    @EE = @_;
    for $T( @EE ) {
    $T =~ s/User-agent: \*//ig;
    $T =~ s/Allow.*//g;
    $X =~ s/\/robots\.txt//ig;
    $T =~ s/Disallow: /{Disallow: (\S+)}{$X\/$1}/ig;
    $T =~ s/\{//ig;
    $T =~ s/\}//ig;
    $T =~ s/\(S\+\)//ig;
    $T =~ s/.*Disallow: //ig;
    $T =~ s/\/\//\//ig;
    $T =~ s/http:\//http:\/\//ig;
    $T =~ s/^\n//ig;
    $T =~ s/^\n//ig;
    # print "$T";
    return $T;
    $T = ();
       }
     }
    }
    Et ce qu'il me retourne


    http://www.google.com/search
    http://www.google.com/groups
    http://www.google.com/images
    http://www.google.com/catalogs
    http://www.google.com/catalog_list
    http://www.google.com/news
    http://www.google.com/nwshp
    http://www.google.com/?
    http://www.google.com/addurl/image?
    http://www.google.com/pagead/
    http://www.google.com/relpage/
    http://www.google.com/sorry/
    http://www.google.com/imgres
    http://www.google.com/keyword/
    http://www.google.com/u/
    http://www.google.com/univ/
    http://www.google.com/cobrand
    http://www.google.com/custom
    http://www.google.com/advanced_group_search
    http://www.google.com/advanced_search
    http://www.google.com/googlesite
    http://www.google.com/preferences
    http://www.google.com/setprefs
    http://www.google.com/swr
    http://www.google.com/url
    http://www.google.com/wml?
    http://www.google.com/xhtml?
    http://www.google.com/imode?
    http://www.google.com/jsky?
    http://www.google.com/pda?
    http://www.google.com/sprint_xhtml
    http://www.google.com/sprint_wml
    http://www.google.com/pqa
    http://www.google.com/palm
    http://www.google.com/hws
    http://www.google.com/bsd?
    http://www.google.com/linux?
    http://www.google.com/mac?
    http://www.google.com/microsoft?
    http://www.google.com/unclesam?
    http://www.google.com/answers/search?q=
    http://www.google.com/local?
    http://www.google.com/local_url
    http://www.google.com/froogle?
    http://www.google.com/froogle_
    http://www.google.com/print?
    http://www.google.com/scholar?
    http://www.google.com/complete
    http://www.google.com/sponsoredlinks
    http://www.google.com/videosearch?
    http://www.google.com/videopreview?
    http://www.google.com/videoprograminfo?
    http://www.google.com/maps?
    http://www.google.com/translate?
    http://www.google.com/ie?
    http://www.google.com/sms/demo?

    alors qu'il faudrait qu'il me retourne celui de msn comme suis :

    http://search.msn.fr/results
    http://search.msn.fr/keepalive/
    http://search.msn.fr/static/
    http://search.msn.fr/w3c/
    http://search.msn.fr/cfgs/
    http://search.msn.fr/schema/
    http://search.msn.fr/kids/
    http://search.msn.fr/Kidz/
    http://search.msn.fr/pass/
    http://search.msn.fr/news/
    http://search.msn.fr/images/

    Ou est le problème
    Everybody have in their the potential to be their own god : Marilyn Manson

  9. #9
    Membre actif
    Inscrit en
    Février 2005
    Messages
    167
    Détails du profil
    Informations forums :
    Inscription : Février 2005
    Messages : 167
    Points : 203
    Points
    203
    Par défaut
    Citation Envoyé par mobscene
    Heu oui c'etait une erreur. Bon j'ai encore un prb avant de faire le ménage dans le prog

    Le script marche bien seulement il ne me retourne que le premier élément du tableau


    Voici le code :


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    #!C:\Perl\bin\perl.exe
     
    # ...
     
    sub find(@)
    {
     my @EE = @_;
    use LWP::Simple;
    for my $URL( @EE ) {
        my $B = get($URL);
        return $B;
      }
    }
     
    ...
    ...
    Ou est le problème
    Ton find() retourne dès qu'il n'a vu que le premier résultat !

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    use LWP::Simple;
     
    sub find {
        my @resultat;
        for my $url( @_ ) {
            push @resultat, get($url);
        }
        return @resultat;
    }
    N

  10. #10
    Membre actif Avatar de mobscene
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    331
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2005
    Messages : 331
    Points : 234
    Points
    234
    Par défaut
    Ben sa donne toujours le même résultat
    Everybody have in their the potential to be their own god : Marilyn Manson

  11. #11
    Membre régulier
    Profil pro
    Inscrit en
    Décembre 2004
    Messages
    210
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2004
    Messages : 210
    Points : 99
    Points
    99
    Par défaut
    Ton problème vient de


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    sub replace(@) 
    { 
    @EE = @_; 
    for $T( @EE ) { 
    $T =~ s/User-agent: \*//ig; 
    $T =~ s/Allow.*//g; 
    $X =~ s/\/robots\.txt//ig; 
    $T =~ s/Disallow: /{Disallow: (\S+)}{$X\/$1}/ig; 
    $T =~ s/\{//ig; 
    $T =~ s/\}//ig; 
    $T =~ s/\(S\+\)//ig; 
    $T =~ s/.*Disallow: //ig; 
    $T =~ s/\/\//\//ig; 
    $T =~ s/http:\//http:\/\//ig; 
    $T =~ s/^\n//ig; 
    $T =~ s/^\n//ig; 
    # print "$T"; 
    return $T; 
    $T = (); 
       } 
     }
    Après un bon moment passé dessu je trouve pas de soluce .

    par contre fait comme sa avec ton script c'est plus propre



    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    #!C:\Perl\bin\perl.exe
     
     
    ##################################
    # Tableau d'adresse(s)
    ##################################
     
    @EE = ("http://www.google.com/robots.txt","http://search.msn.fr/robots.txt"); 
     
     
    for $X( @EE ) {
     
     
    ##################################
    # Appelles des fonctions
    ##################################
     
    @EE = find(@EE); 
    @EE = replace(@EE); 
    print "@EE"; # Récupération de robotx.txt 
     
    ##################################
    # Recherche des robots.txt
    ##################################
     
    sub find {
      use LWP::Simple;
        my @resultat; 
        for my $url( @_ ) { 
            push @resultat, get($url); 
        } 
        return @resultat; 
     }
     
    ##################################
    # Parser robots.txt
    ##################################
     
    sub replace
    {
    for my $T( @_ ) {
    $T =~ s/User-agent: \*//ig; 
    $T =~ s/Allow.*//g; 
    $X =~ s/\/robots\.txt//ig; 
    $T =~ s/Disallow: /$X\/$1/ig; 
    $T =~ s/\/\//\//ig; 
    $T =~ s/http:\//http:\/\//ig; 
    $T =~ s/^\n//ig; 
    $T =~ s/^\n//ig;
    $T =~ s/\n$//ig;
    return $T; 
       } 
     } 
    }
    Il me semble que si LWP ne trouve pas le liens il renvoie undef je suppose que tu a conçue un filtre pour faire ce boulot de gestion des erreurs

    Je pense qu'il faudrais utiliser push() dans replace mais je ne sais pas comment faire , c'est pour sa que je vais aller consulter mon fidèle amie Google

  12. #12
    Membre à l'essai
    Profil pro
    Inscrit en
    Février 2005
    Messages
    43
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2005
    Messages : 43
    Points : 24
    Points
    24
    Par défaut
    Heu j'avoue moi aussi je trouve pas de soluce

    par contre pour être plus " propre" je ferais


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    $T =~ s/^\n*//ig; 
    $T =~ s/\n$//ig;

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Récuparation de l URL de IE
    Par Al_co dans le forum Langage
    Réponses: 4
    Dernier message: 24/04/2008, 08h39
  2. [VB6] fonction d' encodage URL en VB
    Par jeanseb dans le forum VB 6 et antérieur
    Réponses: 2
    Dernier message: 14/01/2003, 11h16
  3. URL d'Internet Explorer
    Par dbourni dans le forum API, COM et SDKs
    Réponses: 5
    Dernier message: 06/12/2002, 08h56
  4. [web] tester la validiter d'une URL
    Par zebiloute dans le forum Web
    Réponses: 4
    Dernier message: 25/11/2002, 16h51
  5. Check Url pour savoir si erreur 404 ou si le site existe
    Par Clément[Delphi] dans le forum Composants VCL
    Réponses: 2
    Dernier message: 07/08/2002, 13h49

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo