Pagina 1 di 4 1 2 3 ... ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 32
  1. #1

    navigare nella pagine web

    qualcuno saprebbe indicarmi come creare un programmino che naviga nel web e clicca sui link? (vorrei provare a fare un bot..... tanto per divertirmi).
    Mi servirebbe solo sapere come fare a richiedere una pagina html, e magari scrivere nei form...

    grazie!

  2. #2
    Non è una cosa facile, soprattutto se non specifichi il linguaggio da utilizzare...
    "Se riesci a passare un pomeriggio assolutamente inutile in modo assolutamente inutile, hai imparato a vivere."

  3. #3
    infatti mi sono accorto che non avevo messo il linguaggio.... =)=) io preferirei il c\c++ ma anche phyton va bene....

  4. #4
    Il problema va scomposto in 3 sottoproblemi:

    1) Come effettuare una richiesta HTTP ad un web-server
    2) Come effettuare il parsing del codice HTML per estrarre i link
    3) Gestire il click sui link (vuoi realizzare un browser/robot visuale? Quale è lo scopo del programma?)

    Sono problemi non banali per un principiante, in particolar modo se non si utilizzano librerie esterne.

    Ovviamente in Python è tutto più semplice.
    "Se riesci a passare un pomeriggio assolutamente inutile in modo assolutamente inutile, hai imparato a vivere."

  5. #5
    Utente di HTML.it L'avatar di mamo139
    Registrato dal
    May 2005
    residenza
    Londra
    Messaggi
    841
    sai gia come sviluppare programmi client o server?? sai usare le socket??

  6. #6
    sai gia come sviluppare programmi client o server?? sai usare le socket??
    Spero tu non voglia consigliargli di fare tutto a mano, se proprio non vuole sfruttare le comodità del Python esistono delle ottime librerie C/C++ che consentono di risolvere i problemi in modo rapido ed elegante... Come dicono gli inglesi: "Don't reinvent the wheel!".

    Per esempio usando la nota Libwww si potrebbe partire da una cosa del genere (60 righe di codice, il fetching delle pagine ed il relativo parsing sono compresi nel prezzo):

    codice:
    /*
    **	@(#) $Id: showlinks.c,v 1.2 1999/03/01 13:41:55 frystyk Exp $
    **	
    **	Other libwww samples can be found at "http://www.w3.org/Library/Examples"
    **	
    **	Copyright (c© 1995-1998 World Wide Web Consortium, (Massachusetts
    **	Institute of Technology, Institut National de Recherche en
    **	Informatique et en Automatique, Keio University). All Rights
    **	Reserved. This program is distributed under the W3C's Software
    **	Intellectual Property License. This program is distributed in the hope
    **	that it will be useful, but WITHOUT ANY WARRANTY; without even the
    **	implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
    **	PURPOSE. See W3C License http://www.w3.org/Consortium/Legal/ for more
    **	details.
    **
    **      Parses a HTML document and prints out all the embedded links to stdout
    */
    
    #include "WWWLib.h"
    #include "WWWInit.h"
    #include "WWWHTML.h"
    
    PRIVATE int printer (const char * fmt, va_list pArgs)
    {
        return (vfprintf(stdout, fmt, pArgs));
    }
    
    PRIVATE int tracer (const char * fmt, va_list pArgs)
    {
        return (vfprintf(stderr, fmt, pArgs));
    }
    
    PRIVATE int terminate_handler (HTRequest * request, HTResponse * response,
    			       void * param, int status) 
    {
        /* We are done with this request */
        HTRequest_delete(request);
    
        /* Terminate libwww */
        HTProfile_delete();
    
        exit(0);
    }
    
    PRIVATE void foundLink (HText * text,
    			int element_number, int attribute_number,
    			HTChildAnchor * anchor,
    			const BOOL * present, const char ** value)
    {
        if (anchor) {
    	/*
    	**  Find out which link we got. The anchor we are passed is
    	**  a child anchor of the anchor we are current parsing. We
    	**  have to go from this child anchor to the actual destination.
    	*/
    	HTAnchor * dest = HTAnchor_followMainLink((HTAnchor *) anchor);
    	char * address = HTAnchor_address(dest);
    	HTPrint("Found link `%s\'\n", address);
    	HT_FREE(address);
        }
    }
    
    int main (int argc, char ** argv)
    {
        char * uri = NULL;
    
        /* Create a new premptive client */
        HTProfile_newHTMLNoCacheClient ("ShowLinks", "1.0");
    
        /* Need our own trace and print functions */
        HTPrint_setCallback(printer);
        HTTrace_setCallback(tracer);
        
        /* Set trace messages and alert messages */
    #if 0
        HTSetTraceMessageMask("sop");
    #endif
    
        /* Add our own termination filter */
        HTNet_addAfter(terminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST);
    
        /*
        ** Register our HTML link handler. We don't actually create a HText
        ** object as this is not needed. We only register the specific link
        ** callback.
        */
        HText_registerLinkCallback(foundLink);
    
        /* Setup a timeout on the request for 15 secs */
        HTHost_setEventTimeout(15000);
    
        /* Handle command line args */
        if (argc >= 2)
    	uri = HTParse(argv[1], NULL, PARSE_ALL);
    
        if (uri) {
    	HTRequest * request = NULL;
    	HTAnchor * anchor = NULL;
    	BOOL status = NO;
    
    	/* Create a request */
    	request = HTRequest_new();
    
    	/* Get an anchor object for the URI */
    	anchor = HTAnchor_findAddress(uri);
    
    	/* Issue the GET and store the result in a chunk */
    	status = HTLoadAnchor(anchor, request);
    
    	/* Go into the event loop... */
    	if (status == YES) HTEventList_loop(request);
    
        } else {
    	HTPrint("Type the URI to print out a list of embedded links\n");
    	HTPrint("\t%s <uri>\n", argv[0]);
    	HTPrint("For example:\n");
    	HTPrint("\t%s http://www.w3.org\n", argv[0]);
        }
    
        return 0;
    }
    "Se riesci a passare un pomeriggio assolutamente inutile in modo assolutamente inutile, hai imparato a vivere."

  7. #7
    allora... io non ho mai scritto programmi client\server quindi non ho idea di come si faccia a far connettere un programma al web (si dice così?) quello che vorrei vare è un piccolo bot che gira su internet o che posta sul forum della mia classe ( non so cosa fargli fare, è solo per provare a a farne uno). Se dite che in c è troppo complesso va benissimo anche il phyron, ho dato un'occhiata al link di pallinopinco e mi sembra più semplice del c....

    non ho capito cos'è il fetching delle pagine.... il parsing da quello che ho capito è la "lettura" della pagina, giusto?

    grazie e tutti!

    Ps: mi servirebbe ache fare in modo che il bot accetti e reinvii i cookie.... (anche lasciando perdere le scadenze)

  8. #8
    Prima ti consiglierei di studiarti un po' le socket e se non vuoi fare tutto tu, puoi usare le ottime http://curl.haxx.se/libcurl/ o le libWWW.
    Per il parsering ho trovato questo:
    http://www.gnu.org/software/libc/man...pressions.html
    che ovviamente utilizza le regex.

    Poi se vuoi farti tutto in python o perl, va bene, ma considerando la tua inesperienza credo che sarebbe molto più "didattico" farlo in C. Ammesso che tu abbia tempo ...


  9. #9
    ho dato un occhiata alle curl e alle libWWW e non ci ho capito molto.... nel tutorial arrivo fino a dove spiega come settare le libcurl ma poi non capisco più...... se qualcuno me le può spiegare da zero sarei contentissimo ..... altrimenti il python mi sembra una buona soluzione(ma anche il avrei bisogno di aiuto..)

  10. #10
    ho dato un occhiata alle curl e alle libWWW e non ci ho capito molto
    Il codice postato qualche messaggio fa si basa sulla libwww ed effettua il fetching (=scaricamento della pagina HTML) e l'estrazione degli indirizzi contenuti nella pagina. Sono solo 60 righe di codice, se ti sembrano difficili da capire significa che ti stai ponendo un obiettivo troppo ambizioso per le tue attuali conoscenze. Cosa non ti è chiaro?

    se qualcuno me le può spiegare da zero sarei contentissimo
    Per questo esistono i manuali e la documentazione ufficiale. In un forum puoi risolvere problemi molto specifici.
    "Se riesci a passare un pomeriggio assolutamente inutile in modo assolutamente inutile, hai imparato a vivere."

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.