悉野小楼

导航

python读取网页

使用自带的urllib.request

import urllib.request

req = urllib.request.Request("http://www.baidu.com")
with urllib.request.urlopen(req) as response:
    data = response.read()
    print(data)

 使用requests库

pip3 install requests

import requests

response = requests.get('http://www.baidu.com')
print(response.text)

 

posted on 2024-08-22 12:00  悉野  阅读(17)  评论(0)    收藏  举报