What's wrong with this code?

Put your programming skills to the test in these challenges.

What's wrong with this code?

Post by Rioghasarig on Tue Aug 10, 2010 6:12 pm
([msg=43529]see What's wrong with this code?[/msg])

So, for fun, I was working on a project to connect a chat bot to omegle and have it have conversations with people. (Well, also to practice my knowledge of HTML requests and learn how omegle works.) I got the omegle side of the things working fine but I was having trouble with the chatbot. I mean, I'm not making my own chatbot. I just want to try it with a chatbot that has already been created and put on the internet. I chose oliverbot (because I have fond memories of having great conversations with it when I was younger.) But, I'm having a bit of trouble. I'm using Python 2.7 and my code is:

Code: Select all
import urllib
import os
from HTMLParser import HTMLParser

class OliverClient(HTMLParser):
    def __init__(self):
        HTMLParser.__init__(self)
        self.session_name = ""
        self.botname = "Oliver"
        self.i = 1
        self.input1 = ""
        self.input = "Stranger"
   
    def handle_starttag(self, tag, attrs):
        print tag
        if tag == "input":
            print "Doing this"
            for name,value in attrs:
                if name == "<?session_name()?>":
                    self.session_name = value
                elif name == "botname":
                    self.botname = value
                elif name == "i":
                    self.i = i
                elif name == "input1":
                    self.input1 = input1
             
    def printVals(self):
        print "session: ", self.session_name
        print "botname: ", self.botname
        print "i: ", self.i
        print "input1: ", self.input1
        print "input: ", self.input


    def makeRequest(self):
        values = {"<?=session_name()?>": self.session_name, "botname": self.botname,
                  "i": self.i, "input1": self.input1, "input": self.input}
        data = urllib.urlencode(values)
        infile = urllib.urlopen("http://www.bored.com/oliverbot/php_chatter/src/talk.php", data)
        s = infile.read()
        self.feed(s)

   

oclient = OliverClient()
oclient.makeRequest()


The problem I'm encountering is that this doesn't go through all the tags on the page, and, thus, doesn't set the values as it should. Now, this isn't really a major set back. I'm just really confused as to why this is occurring. It goes through the first few dozen or so tags and then just stops.

Code: Select all
html
head
meta
meta
meta
meta
title
link
link
link
link
script
script
script
script
script
body
div
div
div
div
h1
a
span
div
div
div
div
div
ul
li


I'm really confused. Anyone have any idea what may be causing this?
Rioghasarig
New User
New User
 
Posts: 2
Joined: Mon Aug 09, 2010 7:29 pm
Blog: View Blog (0)


Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests