高山 发表于 2021-6-25 17:29:17

Python调用

Python如何设置方式,然后调用一个网页内容?

nahongyan1997 发表于 2021-6-25 17:37:19

我喜欢用 urllib 库,python自带,代码:
from urllib.request import urlopen,Request

url = "www.baidu.com"

headers = {"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36"}

Req = Request(url,headers=headers)

html = urlopen(Req).read().decode()

print(html)

qiuyouzhi 发表于 2021-6-25 18:49:55

额,"调用" 是什么意思?
是要提取网页中的信息吗?
页: [1]
查看完整版本: Python调用