Thread: Open a URL

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2005
    Posts
    6
    Rep Power
    0

    Question Open a URL


    Hello, I am very new to Python and have, what I think, is a rather simple question.

    First, I am running Python 2.1 on Win XP. What I want to do is open a CF page after my process has run and pass the processID, that I will set, and the exit code value to it. The CF page will then insert the values to a SQL table. I have tried to just get Python to open a URL using the URLLIB but have been unsuccessful. Here is a sample what I have tried:

    import urllib
    url = ‘http://www.google.com’
    page = urllib.urlopen(url)
    pagedata = page.read()

    Any help would be greatly appreciated. Thanks.

    Also, if there is a way for Python to post to a SQL table directly without using an intermediate CF page I would be interested in learning how. Thanks again.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    624
    Rep Power
    34
    That should work, it works for me...

    Are you at a company where your internet access has to go through a proxy?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2005
    Posts
    6
    Rep Power
    0
    Originally Posted by sfb
    That should work, it works for me...

    Are you at a company where your internet access has to go through a proxy?
    Yes I am. Does that change things?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11
    I would not think so
    but if not then use the urllib and those types of libs
    Last edited by monkeyman23555; August 25th, 2005 at 02:00 PM.
    Those people who think they know everything are a great annoyance to those of us who do.
  8. #5
  9. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    You could also do:
    Code:
    opener = urllib.FancyURLopener({})
    n_url = opener.open('http://www.google.com’)
    for line in n_url.readlines():
        print line
    Last edited by †Yegg†; August 25th, 2005 at 01:38 PM.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2005
    Posts
    6
    Rep Power
    0
    Thanks, that does exactly what I need.

    Now I am having trouble capturing the exit code. Is the returned exit code stored somewhere that I can use. Thanks again everybodys help.
  12. #7
  13. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    What kind of SQL database are you using? Python has quite a quite a few interfaces to SQL databases. You can find a short listing of them in Python DB-SIG. You might also like to try google for more.

    http://www.python.org/topics/database/modules.html

    hope this helps,

    Mark.
    programming language development: www.netytan.com Hula

  14. #8
  15. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Originally Posted by †Yegg†
    You could also do:
    Code:
    opener = urllib.FancyURLopener({})
    n_url = opener.open('http://www.google.com’)
    for line in n_url.readlines():
        print line
    This really shouldn't make any difference at all, if you look at the documentation you'll see that urllib.urlopen() is a convenience function for creating and using an instance of FancyURLopener. So in essence this is just a longer uglier way to do what you've already done .

    Mark.
    programming language development: www.netytan.com Hula

  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11
    whats with the FancyURLopener
    Those people who think they know everything are a great annoyance to those of us who do.
  18. #10
  19. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    As I explained above FancyURLopener is the base class used by the urlopen() function .
    programming language development: www.netytan.com Hula


IMN logo majestic logo threadwatch logo seochat tools logo