Python urllib urlopen not working

后端 未结 8 1097
甜味超标
甜味超标 2021-01-04 07:29

I am just trying to fetch data from a live web by using the urllib module, so I wrote a simple example

Here is my code:

import urllib

sock = urllib         


        
8条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-04 07:43

    In Python3 you can use urllib or urllib3

    urllib:

    import urllib.request
    with urllib.request.urlopen('http://docs.python.org') as response:
        htmlSource = response.read()
    

    urllib3:

    import urllib3
    http = urllib3.PoolManager()
    r = http.request('GET', 'http://docs.python.org')
    htmlSource = r.data
    

    More details could be found in the urllib or python documentation.

提交回复
热议问题