Python获取网页html代码

Posted 看例学习

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python获取网页html代码相关的知识,希望对你有一定的参考价值。

获取网页html代码:

 

import requests
res = requests.get(\'https://www.cnblogs.com/easyidea/p/10214559.html\')
res.encoding = \'utf-8\'
print(res.text)

 

如果不能正常获取说明你还没有安装 requests库,安装requests方法很简单,Windows电脑打开cmd 输入 pip install requests 回车即可,Macos(苹果电脑)打开终端输入 pip install requests 回车即可。

运行结果:

 

以上是关于Python获取网页html代码的主要内容,如果未能解决你的问题,请参考以下文章