Python 获取第一个网页内容
import requests def getHTMLText(url): try: r = requests.get(url, timeput=30) r.raise_for_status() #如果状态不是200,引发异常 r.encoding = ‘utf-8‘ #无论原来用什么编码,都改成utf-8 return r.text except: return "" url = "http://www.baidu.com" print(getHTMLText(url))
相关推荐
HeyShHeyou 2020-11-17
86193952 2020-10-27
小木兮子 2020-11-11
seanzed 2020-10-15
huangliuyu00 2020-09-24
libaoshan 2020-09-11
zhangpan 2020-09-10
chongxiaocheng 2020-08-16
xcguoyu 2020-08-15
Qizonghui 2020-08-02
ldcwang 2020-07-26
mqfcu 2020-07-21
jeason 2020-07-20
sunzhihaofuture 2020-07-19
knightwatch 2020-07-19
点滴技术生活 2020-07-19
Reiki 2020-07-06