plasticuproject / cleverbotfree

Free alternative for the Cleverbot API
GNU General Public License v3.0
58 stars 6 forks source link

Only works the first fifteen times exactly. #3

Closed htahboub closed 4 years ago

htahboub commented 4 years ago

Either this hasn't been tested enough or this just happens on my machine (iMac). In a conversation like this one:-

User: 1 Cleverbot: 2 User: 3 Cleverbot: 4 User: 5 Cleverbot: 6 User: 7 Cleverbot: 8 User: 9 Cleverbot: 10 User: 11 Cleverbot: 12 User: 13 Cleverbot: 14 User: 15

I always get this error right after the fifteenth:-

Traceback (most recent call last):
  File "session_chat.py", line 28, in <module>
    main()
  File "session_chat.py", line 22, in main
    bot = cb.get_response()
  File "......../cbfree.py", line 88, in get_response
    if line.text != newLine and newLine.text != ' ' and newLine.text != '':
  File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webelement.py", line 76, in text
    return self._execute(Command.GET_ELEMENT_TEXT)['value']
  File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webelement.py", line 633, in _execute
    return self._parent.execute(command, params)
  File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.StaleElementReferenceException: Message: The element reference of <p id="line1" class=""> is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed.

I urgently need a fix for this. Thanks.

plasticuproject commented 4 years ago

@HTahboub I created this as a way to side-step their paid API service by directly interacting with their website DOM. It looks like they have recently changed the functionality to use some kind of pagination when your conversation reaches a certain limit, i.e. url + /?1, url + /?2, etc., breaking this library. I'll work on making a fix for this soon, or if you would like to take a stab at it you can issue a Pull Request and I will review it. Thank you for bringing this to my attention.

Edit: Okay I think I have it fixed:

[-] Connecting to Cleverbot.com...
[-] Have a conversation with CleverBot...
[-] Just type "quit" to end the conversation

 USER: 1
 CLEVERBOT:  1 what?
 USER: 2
 CLEVERBOT:  5.
 USER: 3
 CLEVERBOT:  Perp.
 USER: 4
 CLEVERBOT:  1.
 USER: 5
 CLEVERBOT:  0.
 USER: 6
 CLEVERBOT:  2.
 USER: 7
 CLEVERBOT:  21.
 USER: 8
 CLEVERBOT:  7.
 USER: 9
 CLEVERBOT:  8.
 USER: 1
 CLEVERBOT:  Z.
 USER: 2
 CLEVERBOT:  3.
 USER: 3
 CLEVERBOT:  4.
 USER: 4
 CLEVERBOT:  5.
 USER: 5
 CLEVERBOT:  6.
 USER: 6
 CLEVERBOT:  7.
 USER: 7
 CLEVERBOT:  Smirks.
 USER: 8
 CLEVERBOT:  Eight.
 USER: 9
 CLEVERBOT:  Nine.
 USER: 0
 CLEVERBOT:  Roland megőrült.
 USER: 

Just need to make a commit and update PyPi and it will be fixed. I will close this issue when I have it done.

plasticuproject commented 4 years ago

Should be fixed now, updated repository and PyPi. Closing this issue. Please leave a comment if you are still having problems with it and I will reopen the issue.

htahboub commented 4 years ago

Thank you so much—this is perfect.