Search code examples
pythonbrowsersplinterwell-formed

Python Splinter issue


I just installed Splinter, input simple code like below but have error. Can someone help me on this? Thanks.

from splinter import Browser

b=Browser()
url = "http://www.google.com"

b.visit(url)

Error messages:

Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/dist-packages/splinter/driver/webdriver/init.py", line 184, in visit self.driver.get(url) File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 245, in get self.execute(Command.GET, {'url': url}) File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 233, in execute self.error_handler.check_response(response) File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: Target URL www.google.ca is not well-formed. Stacktrace: at FirefoxDriver.prototype.get (file:///tmp/tmpsIlz0H/extensions/[email protected]/components/driver-component.js:10636) at DelayedCommand.prototype.executeInternal_/h (file:///tmp/tmpsIlz0H/extensions/[email protected]/components/command-processor.js:12661) at DelayedCommand.prototype.executeInternal_ (file:///tmp/tmpsIlz0H/extensions/[email protected]/components/command-processor.js:12666) at DelayedCommand.prototype.execute/< (file:///tmp/tmpsIlz0H/extensions/[email protected]/components/command-processor.js:12608)


Solution

  • Try this instead:

    from splinter import Browser
    with Browser() as b:
        b.visit("http://www.google.com")
    

    Docs here: https://splinter.readthedocs.org/en/latest/#sample-code

    The method above handles quitting the browser. Your method, also in the docs, should work (it works for me). Try it again, I've noticed I get almost the same error as yours, if my url is "www.google.com". Make sure you have "http://" part.

    selenium.common.exceptions.WebDriverException: Message: Target URL www.google.com is not well-formed