[Résolu] récupérer texte dans page html
#2
This one, gets song data from first link (in "text" format)
.chanset #channel +radioking to activate on your channel.

this script requires tls : http://sourceforge.net/projects/tls/

tcl
set link "https://www.radioking.fr/widgets/currenttrack.php?radio=2263&format=text"
 
bind time - "* * * * *" radio_chk
 
proc radio_chk {args} {
    foreach chan [channels] {
if {[channel get $chan radioking]} {
     set songdb "radio.db"
     set oldsong [read_song $songdb]
     set newsong [fetch_song $::link]
 #set artist [lindex [split [fetch_song $::link] -] 0]
 #set title [lindex [split [fetch_song $::link] -] 1]
 #if {$artist in [stripcodes bcruag $oldsong] && $title in [stripcodes bcruag $oldsong]} { continue }
 #putserv "PRIVMSG $chan :\002$artist\002 - \00304$title\003"
 #write_song $songdb "\002$artist\002 - \00304$title\003" 
        if {[string match $newsong $oldsong]} { continue }
             putserv "PRIVMSG $chan :$newsong"
             write_song $songdb $newsong 
         }
     } 
}
 
proc fetch_song {url} {
     package require http
     package require tls
     ::http::register https 443 [list ::tls::socket -tls1 0 -ssl3 0]
     set token [::http::geturl $url]
     set data [::http::data $token]
     return $data
     ::http::cleanup $token
     ::http::unregister https
}
 
proc write_song {dbfile data} {
    set fp [open $dbfile w]
    puts $fp $data
    close $fp
}
 
proc read_song {dbfile} {
   if {![file exists $dbfile] || ![file readable $dbfile]} { return 0 }
         set fp [open $dbfile r]
         set dt [gets $fp] 
        close $fp
        return $dt
}
 
setudef flag radioking



and this one for second link you gave. ( for "json" format)
This one requires tcllib's json package and tls : http://sourceforge.net/projects/tls/

tcl
set link "https://www.radioking.fr/widgets/currenttrack.php?radio=2263&format=json"
 
bind time - "* * * * *" radio_chk
 
proc radio_chk {args} {
    foreach chan [channels] {
if {[channel get $chan radioking]} {
      set songdb "radio.db"
      set oldsong [read_song $songdb]
      set songdict [fetch_song $::link]
 #set newsong "\002[dict get $songdict artist]\002 - \00304[dict get $songdict title]\003"
      set newsong "\002[dict get $songdict artist]\002 - \00304[dict get $songdict title]\003 - \037[dict get $songdict cover]\037"
        if {[string match $newsong $oldsong]} { continue }
             putserv "PRIVMSG $chan :$newsong"
             write_song $songdb $newsong 
        }
    } 
}
 
proc fetch_song {url} {
     package require http
     package require tls
     package require json
     ::http::register https 443 [list ::tls::socket -tls1 0 -ssl3 0]
     set token [::http::geturl $url]
     set data [::json::json2dict [::http::data $token]]
     return $data
     ::http::cleanup $token
     ::http::unregister https
}
 
proc write_song {dbfile data} {
    set fp [open $dbfile w]
    puts $fp $data
    close $fp
}
 
proc read_song {dbfile} {
   if {![file exists $dbfile] || ![file readable $dbfile]} { return 0 }
         set fp [open $dbfile r]
         set dt [gets $fp] 
         close $fp
         return $dt
}
 
setudef flag radioking


Répondre Avertir


Messages dans ce sujet
récupérer texte dans page html - par BrYcOu - 16/09/2015, 13:56
RE: récupérer texte dans page html - par heartbroken - 16/09/2015, 21:06

Atteindre :


Utilisateur(s) parcourant ce sujet : 1 visiteur(s)
Tchat 100% gratuit -Discutez en toute liberté