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

前端 未结 5 739
南方客
南方客 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条回答
  •  闹比i
    闹比i (楼主)
    2021-01-30 09:04

    You do not have to install urllib3. You can choose any HTTP-request-making library that fits your needs and feed the response to BeautifulSoup. The choice is though usually requests because of the rich feature set and convenient API. You can install requests by entering pip install requests in the command line. Here is a basic example:

    from bs4 import BeautifulSoup
    import requests
    
    url = "url"
    response = requests.get(url)
    
    soup = BeautifulSoup(response.content, "html.parser")
    

提交回复
热议问题