python如何查看网页代码

(编辑:jimmy 日期: 2024/9/23 浏览:2)

用python查看网页代码的方法:

1、使用“import”导入requests包

import requests

2、使用requests包的get()函数通过网页链接获取网页的源码,然后使用print()语句输出就可以了

python如何查看网页代码

执行结果如下:

python如何查看网页代码

实例扩展:

Python获取网页html代码

获取网页html代码:

import requests
res = requests.get('https://www.jb51.net/更换成你的网页.html')
res.encoding = 'utf-8'
print(res.text)

运行结果:

python如何查看网页代码