20 Aug
duccio

duccio il 20 August 2007 parla di Rails Snippet, Risorse

scRUBYt!: uno strumento potente per il web scraping in Ruby

scRUBYt! estrae contenuto dal Web e lo restituisce in XML. Nell’articolo Scrapin’ Google in no sec c’è un possibile scenario di utilizzo, l’idea è quella di fare una ricerca su google ed estrarre i risultati cercando gli a href ciclando sulle prime due pagine di risultati; questo è l’estratto del codice:

    1 require ‘rubygems’
    2 require ’scrubyt’
    3 google_data = Scrubyt::Extractor.define do
    4    #Perform the action(s)
    5    fetch ‘http://www.google.com/ncr’
    6    fill_textfield ‘q’, ‘ruby’
    7    submit
    8    #Construct the wrapper
    9    link "Ruby Programming Language" do
   10       url "href", :type => :attribute
   11    end
   12    next_page "Next", :limit => 2
   13 end
   14 puts google_data.to_xml

e su pastie.caboo.se potete vedere il risultato; gli scenari di utilizzo sono molti e tutti molto interessanti, lo proverò!

google scenario

3 Commenti a “scRUBYt!: uno strumento potente per il web scraping in Ruby”

  1. Giovanni il 29 November 2007 alle 14:44 dice:

    Salve a tutti ho un problema, scrivendo questo codice:

    —————————————*

    require ‘rubygems’
    require ’scrubyt’

    test_data = Scrubyt::Extractor.define do

    fetch(’https://metalink.oracle.com/metalink/plsql/f?p=130:10:1786236168764095279::::alltext,knowledge,archive,bug,forums,numHits:java,TRUE,TRUE,TRUE,TRUE,100′, :proxy => “proxy:3128″)

    primoTxt=”pt02″
    secondoTxt=”pt
    03″

    filltextfield primoTxt.tos, ‘xxxxxxxx’
    filltextfield secondoTxt.tos, ‘xxxxxxxx’
    submit

    end
    puts testdata.toxml

    ————————————–*

    ruby mi produce questo codice:

    ———————————————*

    c:/ruby/lib/ruby/gems/1.8/gems/scrubyt-0.2.6/lib/scrubyt/core/navigation/navigationactions.rb:97:in findformbasedontag’: undefined methodattributes’ for # (NoMethodError)
    from c:/ruby/lib/ruby/gems/1.8/gems/scrubyt-0.2.6/lib/scrubyt/core/navigation/navigationactions.rb:95:in each’
    from c:/ruby/lib/ruby/gems/1.8/gems/scrubyt-0.2.6/lib/scrubyt/core/navigation/navigationactions.rb:95:infindformbasedontag’
    from c:/ruby/lib/ruby/gems/1.8/gems/scrubyt-0.2.6/lib/scrubyt/core/navigation/navigationactions.rb:88:in lookup
    formfortag’
    from c:/ruby/lib/ruby/gems/1.8/gems/scrubyt-0.2.6/lib/scrubyt/core/navigation/navigationactions.rb:34:infilltextfield’
    from c:/ruby/lib/ruby/gems/1.8/gems/scrubyt-0.2.6/lib/scrubyt/core/shared/extractor.rb:92:in send’
    from c:/ruby/lib/ruby/gems/1.8/gems/scrubyt-0.2.6/lib/scrubyt/core/shared/extractor.rb:92:inmethodmissing’
    from C:/TEMP2/rb4059.tmp:11
    from c:/ruby/lib/ruby/gems/1.8/gems/scrubyt-0.2.6/lib/scrubyt/core/shared/extractor.rb:31:in class
    eval’
    from c:/ruby/lib/ruby/gems/1.8/gems/scrubyt-0.2.6/lib/scrubyt/core/shared/extractor.rb:31:indefine’
    from C:/TEMP2/rb4059.tmp:4
    [MODE] Learning
    [ACTION] Setting proxy: host=, port=<3128>
    [ACTION] fetching document: https://metalink.oracle.com/metalink/plsql/f?p=130:10:1786236168764095279::::alltext,knowledge,archive,bug,forums,numHits:java,TRUE,TRUE,TRUE,TRUE,100
    [ACTION] typing xxxxxxxxx into the textfield named ‘pt_02′
    Complete(1)

    ————————————-*
    Da ciò che pare a me sembra che non trovi il textfield in cui inserire i parametri, ma io o controllato e ricontrollato ed il nome e proprio quello.
    Come posso fare?
    Grazie in anticipo dell’aiuto

  2. duccio il 30 November 2007 alle 13:31 dice:

    Accedendo al link che mi hai mandato
    i due input che ci sono si chiamano hanno come “name” quelli che hai scritto nel post e come id “P101PASSWORD” e “P101USERNAME”, prova a mettere l’id anziché il name!

    Avevi provato a mettere l’id?

  3. Giovanni il 5 December 2007 alle 09:24 dice:

    Ti ringrazio per la risposta, comunque avevo provato a mettere anche gli id, non solo ho provato anche altri metodi ma niente, è come se non trovasse i text_field dove inserire il testo, eppure con altri siti funziona tipo yahoo o youtube, ma questo non ne vuole proprio sapere come devo fare non ne ho più idea HELP!
    Ciao

Scrivi un commento