i have created a web browser in glade / python and what i'm wanting to do is get HTTP:// to load automatically. Just because at the moment whenever i go to a website i have to type the HTTP:// and if i do not type this then the website does not open and i get a error message.

could anyone please help me out with the code or a way to do this please.

  • It works in Firefox. Have you tried Ctrl+Enter? – Mitch Apr 17 '13 at 17:36
  • 2
    Just add a list of protocols (http, https, ftp, etc) and require that the leading blob be one of them. If it's not prepend the default to the string. – RobotHumans Apr 17 '13 at 18:03

Assuming the address entry is called address_entry, try it like this:

url = address_entry.get_text()
if not "://" in url:
    # Is http a sane prefix?
    url = "http://" + url
| improve this answer | |
  • cheers for that i just got it working tonight i was playing about with some code and it started working. self.webview.open("http://" + url) that is the code that got it to work for me – Mattn1014 Apr 18 '13 at 23:02
  • 1
    @DriftedMass: that doesn't sound like a solution to me. What if the user already typed http://? You end up with an invalid http://http://www.ubuntu.com. – Timo Apr 19 '13 at 8:30
  • python is so nice! – don.joey Apr 19 '13 at 10:31
  • So if the user had already typed http:// how do you suggest that i cancel out the script running the http:// bit? – Mattn1014 Apr 19 '13 at 12:23
  • @DriftedMass: see my answer. It will only add http:// if the string :// isn't found in the url. – Timo Apr 19 '13 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.