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

    Join Date
    Sep 2005
    Posts
    12
    Rep Power
    0

    Read website: HTTPBasicAuthHandle


    I found this on the internet. But how do i read te website witch i opened. In other words: How to print the source of this protected page?

    python Code:
     
    import urllib2
     
    password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
    # create a password manager
     
    password_mgr.add_password(None,
        "http://www.fbdirks.nl/bz/index.php","myusername","mypassword")
    # add the username and password
    # if we knew the realm, we could
    # use it instead of ``None``
     
    handler = urllib2.HTTPBasicAuthHandler(password_mgr)
    # create the handler
     
    opener = urllib2.build_opener(handler)
    # from handler to opener
     
    opener.open(http://www.fbdirks.nl/bz/index.php)
    # use the opener to fetch a URL
     
    urllib2.install_opener(opener)
    # install the opener
    # now all calls to urllib2.urlopen use our opener
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,641
    Rep Power
    4247
    Code:
    foo = urllib2.urlopen('http://url.to.open/')
    data = foo.read()
    # Do something here with data.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo

IMN logo majestic logo threadwatch logo seochat tools logo