What should I use to open a url instead of urlopen in urllib3

前端 未结 5 880
南方客
南方客 2021-01-30 08:29

I wanted to write a piece of code like the following:

from bs4 import BeautifulSoup
import urllib2

url = \'http://www.thefamouspeople.com/singers.php\'
html = u         


        
5条回答
  •  南笙
    南笙 (楼主)
    2021-01-30 09:03

    urllib3 is a different library from urllib and urllib2. It has lots of additional features to the urllibs in the standard library, if you need them, things like re-using connections. The documentation is here: https://urllib3.readthedocs.org/

    If you'd like to use urllib3, you'll need to pip install urllib3. A basic example looks like this:

    from bs4 import BeautifulSoup
    import urllib3
    
    http = urllib3.PoolManager()
    
    url = 'http://www.thefamouspeople.com/singers.php'
    response = http.request('GET', url)
    soup = BeautifulSoup(response.data)
    

提交回复
热议问题