Get webpage contents with Python?

前端 未结 8 1525
情话喂你
情话喂你 2020-12-04 15:22

I\'m using Python 3.1, if that helps.

Anyways, I\'m trying to get the contents of this webpage. I Googled for a little bit and tried different things, but they didn\

8条回答
  •  [愿得一人]
    2020-12-04 15:51

    A solution with works with Python 2.X and Python 3.X:

    try:
        # For Python 3.0 and later
        from urllib.request import urlopen
    except ImportError:
        # Fall back to Python 2's urllib2
        from urllib2 import urlopen
    
    url = 'http://hiscore.runescape.com/index_lite.ws?player=zezima'
    response = urlopen(url)
    data = str(response.read())
    

提交回复
热议问题