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

前端 未结 5 849
南方客
南方客 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 08:58

    The new urllib3 library has a nice documentation here
    In order to get your desired result you shuld follow that:

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

    The "decode utf-8" part is optional. It worked without it when i tried, but i posted the option anyway.
    Source: User Guide

提交回复
热议问题