| View previous topic :: View next topic |
| Author |
Message |
retan Voice
Joined: 11 Jun 2007 Posts: 5
|
Posted: Thu Jun 14, 2007 11:26 pm Post subject: Site explorer |
|
|
Hello I'm searching for a script, that searches a string on a webpage and posts it on my irc channel.
Example:
www.test.com/test.html looks like this:
| Quote: | <html>
<body>
<h1>Animal Dog</h1>
</body>
</html> |
# How to output the string? (It has to be $startstring)
When I use $text, it doesnt work!
My Starting:
| Code: | package require http
bind pub - !searchstring searchproc
proc searchproc {nick uhost hand chan text} {
set url "www.test.com/test.html"
set token [::http::geturl $url]
set content [::http::data $token]
::http::cleanup $content
regexp {<h1>$startstring(.*?)</h1>.*?} $fullcontent $stringcontent
if {[info exists $startstring]} {putserv "PRIVMSG $chan : String not found"}
else {putserv "PRIVMSG $chan : $stringcontent} } |
So, my problem is how to tell the script to give out the string_search_text.
How can I do that? |
|
| Back to top |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Fri Jun 15, 2007 6:40 am Post subject: |
|
|
You cant use variables within the regexp like that, although you can use a form like:
| Code: |
set regexvar "h1>$startstring(.*?)</h1>.*?"
regexp $regexvar $content fullcontent stringcontent
|
That should work, assuming $startstring is actually defined (I don't see it defined in your code.)
Note also you made a mistake in using $fullcontent, $stringcontent, instead of just 'fullcontent, stringcontent' in your regexp and you also forgot to put in the $content var.
Actually, now that I look again, your code doesn't make much sense.. The stuff between () in the regexp, is what's going to be captured into $stringcontent. I'm assuming your $startstring is some other content you do *not* want to capture..
If you simply want to capture the entire content between <h1> </h1> then use:
regexp {<h1>(.*?)</h1>} $content fullcontent stringcontent |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|